jmccoy-1028380 (10/1/2012)
Yes! That works as desired. Thank You!Are there other ways though, for evaluating it?
--something like:
IF isnull(@OrderNumRtrn, 0) = 0 OR @OrderNumRtrn = '000000'
PRINT 'Do Something'
ELSE
PRINT 'Do Nothing'
I did not know I couldn't SET @Variable before trying to SELECT into it, and have it be a factor. I guess I'm thinking that SELECTing into the variable would overwrite the initial string value. And, if there is nothing returned by the query,the SELECT would set @Variable to NULL.
The ISNULL function used like this offers no gains - it's a cast and a comparison instead of just a comparison.
SELECTing into a variable will overwrite the initial value. If a single row (and column) is returned, then the variable will be assigned the value. If more than one row is returned, then the variable will be assigned one of the values, probably the first in the result set - depending on how the valus is assigned:
DECLARE @name varchar(20)
SELECT @name = name FROM sys.columns WHERE name = 'xptl'
SELECT @name
-- returns NULL
SET @name = 'xxxx'
SELECT @name = (SELECT name FROM sys.columns WHERE name = 'xptl')
SELECT @name
-- returns NULL
SET @name = 'xxxx'
SELECT @name = name FROM sys.columns WHERE name like 'a%'
SELECT @name
-- returns 'auid', last row value from 13 rows
SET @name = 'xxxx'
SELECT @name = (SELECT name FROM sys.columns WHERE name like 'a%')
SELECT @name
-- error: Subquery returned more than 1 value.
-- This is not permitted when the subquery follows =, !=, <, <= , >, >=
-- or when the subquery is used as an expression.
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden