Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 where clause in insert statement

Author  Topic 

kifeda
Posting Yak Master

136 Posts

Posted - 2007-06-27 : 03:41:43
Hello all,

I've got a question. I have an array that I am inserting into a table. The code is in classic asp and looks like this:

SQL1 = "INSERT INTO transactionz (classid, userid) values (" & listOfAnswers(i) & ",8)

The problem is that I want to only insert values that have the value "1". listofAnsers is an array that returns values of "1" and "2". If there a way to limit the inserts to values of "1". Another words, I want to just insert the values of "1" into the table. I know that you experts would say I should control this on the code side and thats true, however, I can't (because I don't control the code side) so is there a way to do this via SQL? Am I making any sense? I was thinking that I needed to add a "where" clause at the end of the code, but I don't know where to go from here.

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-06-27 : 03:56:36
What is the exact value returned by listOfAnswers(i)?
1 If it is 1,2 then use charindex and substring function
2 In front you can use split function and use first part only

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -