July 19, 2013 at 1:35 pm
I have written an IF ELSE statement into a sproc but I'd like to display the results (as in counts) from the statement in the "Results" pane after the sproc runs. How do I accomplish this?
IF EXISTS ({SELECT Query})
BEGIN
{INSERT Version 1}
END
ELSE
BEGIN
{INSERT version 2}
END
Thx.
John
July 19, 2013 at 1:45 pm
Do you just want to know how many rows were inserted? You could consider @@ROWCOUNT or the OUTPUT clause.
July 19, 2013 at 1:51 pm
To obtain data from a stored procedure you need to have a select. A function can 'return' data if that's what you're looking for-- If you're looking to return something based on some condition.
Below is an extremely basic example of selecting data from a temp table in a SProc
declare @Table_A Table (--Table Column Names and cast types)
--if conditions
insert into @Table_A
--else conditions
insert into @Table_A
select columnNameWithResults from @Table_A
July 20, 2013 at 3:56 am
I am not clear with your requirement..can you please some more detailed information to us.......
_______________________________________________________________
To get quick answer follow this link:
http://www.sqlservercentral.com/articles/Best+Practices/61537/
July 22, 2013 at 8:27 am
Correct, Luis.
I wanted to see how many records were inserted.
July 22, 2013 at 8:33 am
latingntlman (7/22/2013)
Correct, Luis.I wanted to see how many records were inserted.
Then you could simply use
SELECT @@ROWCOUNT
Beware of the possible resets of the @@ROWCOUNT value.
July 22, 2013 at 8:50 am
Voide (7/19/2013)
To obtain data from a stored procedure you need to have a select. ...[/code]
The OUTPUT clause of a DELETE will do just fine
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy