Hi
Since there is no IF {ELSE IF} constructs in TSQL, I assume the following will do the equivalent of ELSE IF, please verify. Thanx :)
IF condition
BEGIN
-- some TSQL
END
ELSE IF condition
BEGIN
-- some TSQL
END
ELSE
BEGIN
-- some TSQL
END
JamesPlease comment on any deviation from standard programming that this IF ELSE IF construct may introduce. I am too novice to see it.
Cheers
James|||This should work, but your code will be more readable if you can use a CASE statement instead.
blindman|||true
but isn't IF and ELSE more efficient than CASE
I assume that because what i said is true in general programming
cheers
james|||For a single criteria IF ELSE is probably more efficient, but when you start nesting IF statements I doubt there is any difference. The db engine has to make the same logical comparisons in either case.
Evaluation of a CASE statement completes as soon as a match is found, and further criteria are not considered. I'm not sure if this is true of nested IF/ELSE statements; ie, the optimizer may evaluate the entire statement. Perhaps someone else on the forum knows how the optimizer handles this scenario.
Truth is, neither of these is a very fast operation when performed against large tables. You gotta do what you gotta do.
blindman|||Originally posted by nano_electronix
Hi
Since there is no IF {ELSE IF} constructs in TSQL, I assume the following will do the equivalent of ELSE IF, please verify. Thanx :)
IF condition
BEGIN
-- some TSQL
END
ELSE IF condition
BEGIN
-- some TSQL
END
ELSE
BEGIN
-- some TSQL
END
James
I think this is the correct solution. Lets say "condition" refers to weekend day, a holiday or a week day flag and "TSQL" refers to three totaly diffrent queries. Your code would be resonable.
Now lets say "TSQL" is identical except for the treatment of a date column and all you want is the words "Holiday", "Weekend" or "Weekday" returned in your query, a CASE statment might be the better choice.
Clear as mud?|||agree :)
Showing posts with label thanx. Show all posts
Showing posts with label thanx. Show all posts
Monday, March 26, 2012
Wednesday, March 7, 2012
Identity Columns
Where do I find the seed and increment values of the identity column in database.
If possile can u suggest query for that Pl.
Thanx in advance
-aliselect
object_name(id) as table_name,
name as column_name,
ident_seed(object_name(id)) as seed,
ident_incr(object_name(id)) as increment,
ident_current(object_name(id)) as last_identity
from
syscolumns
where
autoval is not null
and colstat & 1 = 1
and status & 0x80 = 0x80
and columnproperty(id,name,'IsIdentity') = 1
Hope, this helps.
If possile can u suggest query for that Pl.
Thanx in advance
-aliselect
object_name(id) as table_name,
name as column_name,
ident_seed(object_name(id)) as seed,
ident_incr(object_name(id)) as increment,
ident_current(object_name(id)) as last_identity
from
syscolumns
where
autoval is not null
and colstat & 1 = 1
and status & 0x80 = 0x80
and columnproperty(id,name,'IsIdentity') = 1
Hope, this helps.
Subscribe to:
Posts (Atom)