28. Oktober 2020 11:06
28. Oktober 2020 12:00
28. Oktober 2020 12:06
28. Oktober 2020 12:39
InfoWissler hat geschrieben:Allerdings fehlen da Tabellen, die auf jeden Fall ein Integer-Feld als Primärschlüssel haben, z.B. die Cust. Ledger Entry werden da nicht aufgeführt im Ergebnis.
SELECT MAX(column_name)
FROM TableXYZ
28. Oktober 2020 16:05
NewFile.CREATE('\\Netzlaufwerk\IntegerValues.csv');
lim := ';';
NewFile.TEXTMODE(TRUE);
Field.SETRANGE(Type, Field.Type::Integer);
Field.SETRANGE(Class, Field.Class::Normal);
Field.SETRANGE(Enabled, TRUE);
Field.SETFILTER(TableName, '<>CRM*');
Functions.Progressbar('INIT', 'Feldnr.', Field.COUNT, 0, '');
Field.FIND('-');
REPEAT
Functions.Progressbar('UPDATE', '', 0, 100, COPYSTR(Field.TableName + ' ' + Field.FieldName,1,20));
IF OldTableNo <> Field.TableNo THEN BEGIN
RecRef.CLOSE;
RecRef.OPEN(Field.TableNo);
END;
IF RecRef.READPERMISSION THEN BEGIN
IF NOT RecRef.ISEMPTY THEN BEGIN
RecRef.FINDLAST;
FRef := RecRef.FIELD(Field."No.");
NewFile.WRITE(Field.TableName + lim + Field.FieldName + lim + FORMAT(FRef.VALUE));
END;
END;
OldTableNo := Field.TableNo;
UNTIL Field.NEXT = 0;
Functions.Progressbar('CLOSE', '', 0, 0, '');
NewFile.CLOSE;
USE <Database>
GO
DECLARE @DatabaseName VARCHAR(100)
DECLARE @SchemaName VARCHAR(100)
DECLARE @TableName VARCHAR(100)
DECLARE @ColumnName VARCHAR(100)
DECLARE @FullyQualifiedTableName VARCHAR(500)
DECLARE @DataType VARCHAR(50)
--Create Temp Table to Save Results
IF OBJECT_ID('tempdb..#Results') IS NOT NULL
DROP TABLE #Results
CREATE TABLE #Results (
DatabaseName VARCHAR(100)
,SchemaName VARCHAR(100)
,TableName VARCHAR(100)
,ColumnName VARCHAR(100)
,ColumnDataType VARCHAR(50)
,MaxValue VARCHAR(50)
,MinValue VARCHAR(50)
)
DECLARE Cur CURSOR
FOR
SELECT DB_Name() AS DatabaseName
,s.[name] AS SchemaName
,t.[name] AS TableName
,c.[name] AS ColumnName
,'[' + DB_Name() + ']' + '.[' + s.name + '].' + '[' + t.name + ']' AS FullQualifiedTableName
,d.[name] AS DataType
FROM sys.schemas s
INNER JOIN sys.tables t ON s.schema_id = t.schema_id
INNER JOIN sys.columns c ON t.object_id = c.object_id
INNER JOIN sys.types d ON c.user_type_id = d.user_type_id
WHERE d.name LIKE '%int%'
OR d.name LIKE '%float%'
OR d.name LIKE '%decimal%'
OR d.name LIKE '%numeric%'
OR d.name LIKE '%real%'
OR d.name LIKE '%money%'
AND is_identity = 0
OPEN Cur
FETCH NEXT
FROM Cur
INTO @DatabaseName
,@SchemaName
,@TableName
,@ColumnName
,@FullyQualifiedTableName
,@DataType
WHILE @@FETCH_STATUS = 0
BEGIN
DECLARE @SQL VARCHAR(MAX) = NULL
SET @SQL = ' Select ''' + @DatabaseName + ''' AS DatabaseName, ''' + @SchemaName + ''' AS TableName,
''' + @TableName + ''' AS SchemaName,
''' + @ColumnName + ''' AS ColumnName,
''' + @DataType + ''' AS ColumnName,
(Select MAX([' + @ColumnName + ']) from ' + @FullyQualifiedTableName + ' with (nolock))
AS MaxValue,
(Select MIN([' + @ColumnName + ']) from ' + @FullyQualifiedTableName + ' with (nolock))
AS MaxValue'
PRINT @SQL
INSERT INTO #Results
EXEC (@SQL)
FETCH NEXT
FROM Cur
INTO @DatabaseName
,@SchemaName
,@TableName
,@ColumnName
,@FullyQualifiedTableName
,@DataType
END
CLOSE Cur
DEALLOCATE Cur
SELECT *
FROM #Results
--drop table #Results