forked from MRGhidini/SAP_Queries
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUTIL ArrumarTamanhoDeCamposUsuario.sql
66 lines (37 loc) · 1.54 KB
/
UTIL ArrumarTamanhoDeCamposUsuario.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
declare @TableID nvarchar(20);
declare @AliasId nvarchar(18);
declare @EditSize smallint;
declare @SizeID smallint;
declare @RealSize int;
declare @statement nvarchar(max);
declare @params nvarchar(max);
declare alfa_udfs cursor for
select TableID, AliasID, EditSize, SizeID from cufd where TypeID = 'A';
open alfa_udfs;
FETCH NEXT FROM alfa_udfs
INTO @TableID, @AliasId, @EditSize, @SizeID;
WHILE @@FETCH_STATUS = 0
BEGIN
IF EXISTS (SELECT * FROM sys.tables WHERE name = @TableId)
BEGIN
set @RealSize = 0
set @params = '@RealSizeOut int output';
set @statement = 'select @RealSizeOut = max(len(U_' + @AliasID + ')) from [' + @TableId + '] where U_' + @AliasID +' is not null';
EXECUTE sp_executesql @statement, @params, @RealSizeOut = @RealSize OUTPUT;
if @RealSize is not null
BEGIN
if @EditSize < @RealSize
BEGIN
select @TableID As TableName, 'U_' + @AliasId As UDFName, @RealSize As RealSize, @EditSize As DefinedSize, @SizeID as DefinedSize2
END
else if @SizeID < @RealSize
BEGIN
select @TableID As TableName, 'U_' + @AliasId As UDFName, @RealSize As RealSize, @EditSize As DefinedSize, @SizeID as DefinedSize2
END
END
END
FETCH NEXT FROM alfa_udfs
INTO @TableID, @AliasId, @EditSize, @SizeID;
END
CLOSE alfa_udfs;
DEALLOCATE alfa_udfs;