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 2000 Forums
 SQL Server Development (2000)
 Converting Dynamic SQL into SP

Author  Topic 

debradeng
Starting Member

46 Posts

Posted - 2006-10-20 : 03:50:03
I have two queries,they have same functiion,that is to select same data from same joined tables.The only difference is they need different parameters.
Query1:
Select ... from...
where (table1.field1=@param1)AND(table2.field3=@param2)

Query2:
Select ... from...
where (table2.field1=@param1)
I get a feeling that I can create one SP to perform these two queries.But I don't know how to do.

Anybody has some suggestions?

Thank you!

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2006-10-20 : 04:41:26
[code]If (some condition)
Select .... From ....
where (table1.field1=@param1)AND(table2.field3=@param2) -- query 1
Else
Select .... From ....
where (table2.field1=@param1) -- query 2
End[/code]

???

Harsh Athalye
India.
"Nothing is Impossible"
Go to Top of Page

debradeng
Starting Member

46 Posts

Posted - 2006-10-20 : 21:27:53
Thank you, Harsh_athalye.

Maybe I did not make myself clear,but good to know the "IF...Else.." idea!

I really appreciate!
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-10-21 : 01:25:01
Make sure you follow

If ...
Begin
..........
End
Else
Begin
..........
End

Madhivanan

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

- Advertisement -