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.
| Author |
Topic |
|
jrockfl
Posting Yak Master
223 Posts |
Posted - 2005-02-04 : 11:25:14
|
| Is it possible to combine 2 procedures into 1?If the first query doesnt return a result, it would then run the 2nd one. Is this good practice?/* Stored Procedure SalePriceLevels checks for monthly special pricing */CREATE Procedure SalePriceLevels( @Item_No nvarchar(50), @Start_Dt int, @End_Dt int)ASSELECT prod_cat, minimum_qty_1, minimum_qty_2, minimum_qty_3, minimum_qty_4, minimum_qty_5, prc_or_disc_1, prc_or_disc_2, prc_or_disc_3, prc_or_disc_4, prc_or_disc_5, price_uomFROM IMITMIDX_SQLINNER JOIN OEPRCFIL_SQL ON IMITMIDX_SQL.prod_cat = Substring(OEPRCFIL_SQL.Filler_0001,6,9)WHERE (IMITMIDX_SQL.item_no = @Item_No)AND Start_Dt >= @Start_DtAND End_Dt <= @End_DtAND OEPRCFIL_SQL.Filler_0001 LIKE '02%'/* If the first query doesn't return a result then run this one */Create Procedure PriceLevels( @Item_No nvarchar(50))ASSELECT prod_cat, minimum_qty_1, minimum_qty_2, minimum_qty_3, minimum_qty_4, minimum_qty_5, prc_or_disc_1, prc_or_disc_2, prc_or_disc_3, prc_or_disc_4, prc_or_disc_5, price_uomFROM IMITMIDX_SQL INNER JOIN OEPRCFIL_SQL ON OEPRCFIL_SQL.Filler_0001 LIKE IMITMIDX_SQL.prod_cat + '%'WHERE (IMITMIDX_SQL.item_no = @Item_No) |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2005-02-04 : 11:29:35
|
it depens on what you want to do if it's good or bad select * from Table1if @@rowcount = 0begin select * from Table2endGo with the flow & have fun! Else fight the flow |
 |
|
|
jrockfl
Posting Yak Master
223 Posts |
Posted - 2005-02-04 : 13:40:11
|
| Thank you, it works the way I want it in EM, but run i run it in QA, it returns 2 result panes, the first with no values and the second with values |
 |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2005-02-05 : 08:02:08
|
of course it returns 2 panels. it runs 2 queries.if you want to return only one resultset use:if not exisits(select * from Table1)select * from Table2elseselect * from Table1Go with the flow & have fun! Else fight the flow |
 |
|
|
jrockfl
Posting Yak Master
223 Posts |
Posted - 2005-02-05 : 09:20:29
|
| Perfect! That works great for me. That is exactly what I needed.Thank you, I learned a lot by your posts. |
 |
|
|
|
|
|
|
|