Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
if column3 = 1BEGIN SELECT columm1, column2, column3 FROM table1 WHERE column1 = column2END ELSE SELECT columm1, column2, column3 FROM table1END
As you notice, the only difference is the where statementMy actual code contains 10 repetitions of this depending on the category the user chose that is why i want to shorten this.My Question is: is there a way to shorten this?
raky
Aged Yak Warrior
767 Posts
Posted - 2009-01-29 : 05:25:23
try thisSELECT columm1, column2, column3 FROM table1 WHERE ( column3 = 1 AND (column1 = column2)) OR column3 <> 1
SwePeso
Patron Saint of Lost Yaks
30421 Posts
Posted - 2009-01-29 : 05:26:09
[code]SELECT Col1, Col2, Col3FROM Table1WHERE (Col1 = Col2 AND Col3 = 1) OR Col3 <> 1[/code]E 12°55'05.63"N 56°04'39.26"