0

I have written a stored procedure given below....it should print the values I am printing using PRINT command. But rather printing these values, when I executed this procedure from Query Analyzer its shows 'The command(s) completed successfully'. Can u suggest any modification in code or other solutions

Thanks in advance... :)

CREATE PROCEDURE getPullCords(@start_dt varchar(25),@end_dt varchar(25)) AS declare @t varchar(25),@p varchar(50),@v int declare @mycur CURSOR SET @mycur = CURSOR FAST_FORWARD FOR select timestamp,point_id,_val from tcf1_pullcord where timestamp between @start_dt and @end_dt OPEN @mycur FETCH NEXT FROM @mycur INTO @t,@p,@v WHILE @@FETCH_STATUS = 0 BEGIN PRINT @t PRINT @p PRINT @v FETCH NEXT FROM @mycur INTO @t,@p,@v END CLOSE @mycur DEALLOCATE @mycur GO 
1
  • Are you using SQL Server Management Studio (Express)? Commented Dec 6, 2011 at 4:12

5 Answers 5

4

Right click in Query Window > Connection > Disconnect. Then push F5 or execute; Login will display. Login. If you get an error message at first, add a USE statement or fix the error, then retry the above steps. Your cursor will now execute at least once and display results before you need to follow the steps again.

If you execute again during the same session you will notice the same message:

Command(s) completed successfully. 

Very strange bug...

Sign up to request clarification or add additional context in comments.

Comments

3

The output from the print statement does not go to the query results window. It's been a while since I've used Query Analyzer (vs management studio), but look for a separate "Messages" tab and you should find your print output there.

2 Comments

Its shows this message in 'Messages' window itself....while grid window is empty....
@Dharmesh Ctrl+T will switch it into text output so they'll be no grid at all if you don't like the empty grid output. Ctrl+D will switch it back. This works in Query Analyzer and SSMS.
3

Run the command:

select timestamp,point_id,_val from tcf1_pullcord where timestamp between @start_dt and @end_dt 

on its own (substituting the @start_dt and @end_dt vars for the values you're testing with). Does it return any rows? If not, the procedure is never entering the while loop and printing anything.

If it does return rows, try placing a PRINT 'test' outside the loop to ensure it is behaving correctly.

1 Comment

Hey Thanks...YA you are absolutely right....I was entering wrong date range. No data available between these date range..
1

Whatever you've written to print data is correct.

However, if there is data to print then it is printing and you'll not be able to the printed data Results tab.

To see your printed data choose Messages tab of the result section.

Thanks.

1 Comment

hey thanks....actually i forgot that database has been changed recently. There was no data between the date range I was passing..
0

Ran into an issue with a stored procedure printing Command(s) completed successfully instead of returning the result set and thought of the solution while viewing this thread. I'm posting in case anyone else can benefit.

My issue was the size of the parameter passed was larger than the variable I was passing it to. This was running through my stored procedure by-passing all logical arguments because it met none of the criteria.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.