Hey all! Sadly to say, I use MS Access at work and I'd love to know if SQL supports conditional statements like the IF statement. If so, how is it implemented? I know MySQL can use it, that's why I'm wondering.
Steve
Steve
declare @myVar int
...
if (@myVar=0)
begin
...
end
else
begin
...
end
select case when (columnA=value)
then 'yes'
else 'no'
end
...
LtRammstein said:Hey all! Sadly to say, I use MS Access at work and I'd love to know if SQL supports conditional statements like the IF statement. If so, how is it implemented? I know MySQL can use it, that's why I'm wondering.
Steve
Yup it does. The IF statement is exactly the same on MSSQL. Never used the while construct before.robbieduncan said:MS SQL Server (which was based of a version os Sybase some time back) probably supports Transact-SQL syntax as well.
SELECT ISNULL(Col, "default value") FROM x
maxvamp said:MSSQL DOES make available IF statements, but I thought I saw someone mention a WHILE LOOP.
A Major performance warning.... Do your best not to use cursors ( often used with While...If statements ) when possible, and benchmark anything that looks like it might.
The concept of a cursor or While Loops in T-SQL is really slow, as you are traversing every row of a result set, and Indexes become moot.
Max.