SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Removing condition Where
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

j0shua
Starting Member

40 Posts

Posted - 01/29/2009 :  05:22:40  Show Profile  Reply with Quote
Hi, my code is like this


if column3 = 1
BEGIN
  SELECT  columm1,
          column2,
          column3
  FROM 	  table1
  WHERE	  column1 = column2
END 
ELSE
  SELECT  columm1,
          column2,
          column3
  FROM 	  table1
END 



As you notice, the only difference is the where statement
My 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 - 01/29/2009 :  05:25:23  Show Profile  Reply with Quote
try this

SELECT columm1,
column2,
column3
FROM table1
WHERE ( column3 = 1 AND (column1 = column2)) OR column3 <> 1
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

Sweden
30099 Posts

Posted - 01/29/2009 :  05:26:09  Show Profile  Visit SwePeso's Homepage  Reply with Quote
SELECT	Col1,
	Col2,
	Col3
FROM	Table1
WHERE	(Col1 = Col2 AND Col3 = 1)
	OR Col3 <> 1



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

j0shua
Starting Member

40 Posts

Posted - 01/29/2009 :  06:12:19  Show Profile  Reply with Quote
thank you!! everything is clear to me now!
Go to Top of Page

raky
Aged Yak Warrior

767 Posts

Posted - 01/29/2009 :  06:15:44  Show Profile  Reply with Quote
Welcome...
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000