Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Educating myself in TSQL, Part 1...

Author  Topic 

JaybeeSQL
Posting Yak Master

112 Posts

Posted - 2013-09-14 : 14:32:15
Hi all,

I'm an Admin of many years experience but have never had a good training course in coding, I would like to add tracts of code here on SQLTeam and hopefully someone can walk me through:

1) What they do;

2) How they work.

Just so you know, I have a LOT of posts on here in Admin terms so rest assured, I'm not some student asking for you guys to do homework for me!! I will paste both the code I am having difficulty reading, and my own understanding of it (however spotty).

Cheers, JB

---------------------------------------------
DECLARE @Filter varchar(max)

SET @Filter = ''

-- ((ISNULL(<ColumnName>)?"":<ColumnName>)!=(ISNULL(Dest_<ColumnName>)?"":Dest_<ColumnName>)) ||

SELECT @Filter = @Filter + '((ISNULL(' + c.[name] + ')?"":' + c.[name] + ')!=(ISNULL(Dest_' + c.[name] + ')?"":Dest_' + c.[name] + ')) || '

FROM sys.tables t

INNER JOIN sys.columns c

ON t.[object_id] = c.[object_id]

WHERE SCHEMA_NAME( t.[schema_id] ) = 'GroupHealth'

AND t.[name] = 'ConsumerDetail'

AND c.[is_identity] = 0

AND c.[is_rowguidcol] = 0

ORDER BY

c.[column_id]

SET @Filter = LEFT( @Filter, LEN( @Filter ) - 2 )

SELECT @Filter

------------------------

My understanding :

A variable called 'Filter' is declared, and is assigned column names from the system 'Tables' table, the joined to the system 'Columns' table on common object ID's, and 3 other conditions.

However I don't understand all those 'isnull's, why the set/selects on line 4 starts being commented out, all those 'greater than' signs, and the overall logic of the script!!

If anyone could help explain this logically and make it coherent for me, I'd be grateful!!

Cheers,


JB
   

- Advertisement -