@@ROWCOUNT will return the number of rows affected by your query (could be select, insert, delete, or update)
Meanwhile, if you are using SQL Svr 2005/2008, you can also look into the MERGE statement. It allows you to do 3 diff. operations in 1 query: something like define source resultset and target if exists, update if not, insert if not exists in source, delete regards, DK ----- Original Message ----- From: "Michael Dinowitz" <[email protected]> To: "sql" <[email protected]> Sent: Tuesday, April 20, 2010 12:29 PM Subject: query returns data comparison statement > > Hi all, > > I'm trying to optimize a query combination. In CF I'd do a select > statement and if there was no rows returned from the select, I'd do an > insert. Basically I'm making sure a value does not exist before > entering it. > I'm thinking that putting this logic into a stored procedure might be > a good idea. The only problem is, I don't (currently) know how to do > the part where I check if the select returns data. Is there a MS SQL > function to say queryreturnsdata() or the like? Is there a better way? > > Thanks > > -- > Michael Dinowitz > > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| Want to reach the ColdFusion community with something they want? Let them know on the House of Fusion mailing lists Archive: http://www.houseoffusion.com/groups/sql/message.cfm/messageid:3324 Subscription: http://www.houseoffusion.com/groups/sql/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/groups/sql/unsubscribe.cfm
