tags:

views:

58

answers:

3

I found similar questions with correct answers. But they're a bit complicated for me. I just want a simple basic statement.

I have:

string sql = "UPDATE tblPopUp 
                 SET PopUp = 'False' 
               WHERE DisplayNo = 1"

...and:

string sql1 = "SELECT Period  
                 FROM tblPopUp 
                WHERE DisplayNo = 1"

How can I combine them?

+3  A: 

You can't.

There's no convention in a SQL UPDATE statement for returning data. And vice versa -- a SELECT statement doesn't write information to a table.

If you've found questions/answers that you feel are similar to what you want, please provide links.

OMG Ponies
Morning. I know this MySQL question, but SQl Server has something of this sort. http://msdn.microsoft.com/en-us/library/ms177564.aspx Dont know about MySQL...
astander
@astander: Almost bed time here :) No OUTPUT clause or similar that I'm aware of in MySQL - Oracle (and PostgreSQL?) has the RETURNING clause which are very similar to TSQL's OUTPUT clause. None are ANSI, to my knowledge.
OMG Ponies
Aggreed. Its is DB Specific X-(. Good night. See later...
astander
@astander: Good to see you 'round, take care
OMG Ponies
these r the links.. not sure they r the correct ones..http://stackoverflow.com/questions/3779786/update-table-with-a-select-query-with-a-where-clausehttp://stackoverflow.com/questions/562693/mysql-update-and-select-in-one-passhttp://stackoverflow.com/questions/1666485/making-select-and-update-in-one-query
william
OMG, It is Possible as per my answer try it.
mahesh
+1  A: 

Try This

UPDATE tblPopUp 
             SET PopUp = 'False' 
           WHERE DisplayNo = '1'
(
SELECT Period  
             FROM tblPopUp 
            WHERE DisplayNo = '1'
)
mahesh
+2  A: 

UPDATE tblPopUp
SET PopUp = 'False', Period = Period
OUTPUT DELETED.Period WHERE DisplayNo = 1

For more information about OUTPUT clause please check this post:

http://blog.sqlauthority.com/2007/10/01/sql-server-2005-output-clause-example-and-explanation-with-insert-update-delete/

Subhash