Click here to Skip to main content
15,886,422 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I made an sql query for a transaction, when I execute the query it is successful however it only displays a message not the results of the query. How do I change it so the results of the query are displayed when I execute it.

Heres the query

SQL
BEGIN TRAN

UPDATE  Fish
SET FishType = 'Cod'
WHERE   id = '3'

COMMIT TRAN
Posted
Updated 8-Jan-12 2:57am
v2

Without the query its quite impossible to figure out what is going on.
However, make sure you have values that can be returned after applying all the where clauses (from the query) to the tables.
 
Share this answer
 
Comments
Wendelius 8-Jan-12 8:48am    
So true, 5+.
Abhinav S 8-Jan-12 23:46pm    
Thanks.
Youngguns 8-Jan-12 8:58am    
I've added my query to the question.
Monjurul Habib 8-Jan-12 9:54am    
5!
Abhinav S 8-Jan-12 23:46pm    
Thanks.
As Abhinav said, you should post the relevant pieces of code. Also if you're for example calling a stored procedure, check that you don't have NOEXEC on, see: SET NOEXEC[^]
 
Share this answer
 
Comments
Youngguns 8-Jan-12 8:58am    
I've added my query to the question.
Wendelius 8-Jan-12 9:02am    
Since this is an UPDATE statement, it isn't supposed to return the contents of the modified rows, just the amounf of the rows affected. If you want it to return some actual modified data you have to include OUTPUT clause, see: OUTPUT Clause[^]
Youngguns 8-Jan-12 9:13am    
Would I also need to use the output clause if it was an insert statement?
Wendelius 8-Jan-12 9:19am    
Yes, if you want to return the values. In many cases the output isn't needed since the program knows what's added but if triggers etc are involved the using OUTPUT is the solution to get the values. Another option would be to select the row again, but that would require an extra round-trip.
Monjurul Habib 8-Jan-12 9:53am    
5!
Mika already provide a good solution for using OUTPUT Clause. I just want to add one more if you are using SQL Server 2008:
"SQL Server 2005 introduced the new features of after update, after insert and after delete triggers that almost solved the problem of tracking changes in data. A better solution was introduced in SQL Server 2008 and is called Change Data Capture (CDC)." Ref. : Introduction to Change Data Capture (CDC) in SQL Server 2008
 
Share this answer
 
v2
Comments
Abhinav S 8-Jan-12 23:47pm    
Good additional point. For some reason system is just not allowing me to vote a 5.
Monjurul Habib 9-Jan-12 1:34am    
thank you
Wendelius 8-Jan-12 23:57pm    
Good addition. I would also vote but seems that there are big problems with CP working right now
Monjurul Habib 9-Jan-12 1:35am    
thank you
Wendelius 9-Jan-12 13:45pm    
And now the vote should also be in place since it seemed to work again :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900