May 2, 2011 at 2:40 pm
I am truncated with some T-SQL statements.
The objective is to check for an empty string AND a Null value within a specific column of data in a row.
Take my example below:
CREATE PROCEDURE getIDs
@globalID varChar(50)
SELECT DISTINCT ISNULL(1stID, 2ndID) theID
FROM dbo.tableName
WHERE globalID = @globalID
-- What I have here is code that check to see if the 1stID is Null and if so, check the 2ndID and call it 'theID'...
-- What I need now is to also check to see if the 1stID or 2ndID returns empty or nothing in the column, in addition to NULL
I was pondering on using CASE statements then also IF/Else... but obviously became truncated.:w00t:
any ideas? examples?
May 2, 2011 at 2:46 pm
Use an IF EXISTS for your select statement and at the end assign the value to an output variable.
May 2, 2011 at 2:48 pm
See my blog http://sqlscape.blogspot.com (post: SSIS Execute task failure) for examples.
May 3, 2011 at 6:42 pm
Use NULLIF function:
SELECT DISTINCT ISNULL(NULLIF(1stID, ''), NULLIF(2ndID, '')) theID
_____________
Code for TallyGenerator
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply