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.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 if statement

Author  Topic 

mapidea
Posting Yak Master

124 Posts

Posted - 2009-09-08 : 01:47:58
The following if else doesn't work

ALTER PROCEDURE [dbo].[test]
@test varchar(20)
AS
SELECT tb_entry.[feature_id],tb_entry.[user_id]
FROM [tb_profile_feature_entry] AS tb_entry

IF @test="something"
begin
WHERE tb_entry.[user_id] = @test
END

Is there is alternative to acheive the same result.

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-09-08 : 02:05:01
SELECT tb_entry.[feature_id],tb_entry.[user_id]
FROM [tb_profile_feature_entry] AS tb_entry
where (@test="something" and tb_entry.[user_id] = @test)
or @test is null



No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

mapidea
Posting Yak Master

124 Posts

Posted - 2009-09-08 : 02:51:01
Thanks Fred.
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-09-08 : 02:57:20
welcome


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-09-08 : 04:09:00
What if @test is not null?

SELECT tb_entry.[feature_id],tb_entry.[user_id]
FROM [tb_profile_feature_entry] AS tb_entry
where (@test='something' and tb_entry.[user_id] = @test)
or @test<>'something'

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-09-08 : 04:17:53
yes sir!



No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page
   

- Advertisement -