SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Educating myself in TSQL, Part 1...
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

JaybeeSQL
Posting Yak Master

112 Posts

Posted - 09/14/2013 :  14:32:15  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.09 seconds. Powered By: Snitz Forums 2000