I need to build a stored procedure that decides which statement should be ran (either an update or an insert) based off of a value it will receive from an asp.net page. The value being sent to my stored procedure will be checked against a table to see if that value exists.I Loop through values in a ListBox and send them to the stored procedure:storeID and profileID are sent to stored procedure. if storeID is IN table { set update parameters: storeID and profileID update() } if storeID is NOT IN table { set insert parameters: storeID and profileID insert() }Here is how I'm figuring out which storeID's are currently in the Profile Table. I'm coloring those stores red in a page of my project. select Store.storeID, Store.storeName into #temp2from Store join Org on store.orgID = Org.orgID left join [Profile] on store.storeID = [Profile].storeIDwhere [Profile].storeID is not nullselect Store.storeID, Store.storeName, t.StoreID, (case when t.StoreID is not null then 'Yes' else 'No' end) as inProfile from Store join Org on store.orgID = Org.orgID left join [Profile] on store.storeID = [profile].storeID left join #temp2 t on store.storeID = t.storeID where Org.orgID = @orgIDdrop table #temp2
Not sure if it would help, but here is how I would do it in classic asp w/vb scripting:Set Conn = Server.CreateObject("ADODB.Connection")set rs=Server.CreateObject("ADODB.recordset")Conn.open ConnectionStringsql = "select storeID from [Profile] where storeID = '"&storeID&"'" rs.open sql,Conn,3,3 If rs.recordcount <> 0 Then Update Statement goes here else Insert Statement goes here end if Thanks for any help or suggestions. I'm pretty lost as to how to use conditional statements in SQL.