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)
 Conditional Where Clause

Author  Topic 

vaibhavktiwari83
Aged Yak Warrior

843 Posts

Posted - 2010-04-16 : 07:22:45
My proc is something like this

CREATE PROC DeleteSchedule
(
@ID BIGINT
@T_ID BIGINT
@R_ID BIGINT
)
AS
BEGIN

DELETE FROM testtable
WHERE ID = @ID
AND T_ID = @T_ID
AND R_ID = @R_ID

END


IF @R_ID is not null THEN
I want to execute delete command with checking R_ID
And if its null then i dont want to check R_ID condition

How can i do ??
Please help me out...

Vaibhav T

To walk FAST walk ALONE
To walk FAR walk TOGETHER

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-04-16 : 07:28:16
"AND (@R_ID IS NULL OR R_ID = @R_ID)" instead of "AND R_ID = @R_ID"


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

vaibhavktiwari83
Aged Yak Warrior

843 Posts

Posted - 2010-04-16 : 07:42:01
Yes It goes,
Thank you very much webfred...
I solved my problem.

Vaibhav T

To walk FAST walk ALONE
To walk FAR walk TOGETHER
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-04-16 : 07:44:55
welcome


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

- Advertisement -