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
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Help with insert statement (Done through ASP)

Author  Topic 

jose1lm
Yak Posting Veteran

70 Posts

Posted - 2005-09-01 : 12:49:07
I am having trouble getting an INSERT statement to work correctly. I most likely have the statement written wrong so if someone could please help me.

1st: The asp page gathers an employees pin number
2nd: It then gathers a list of documents (WI) to copy into their records from another source. This list is put into a string.

What I want to happen is, take that employee PIN and add all the documents (WI) that are listed in that string variable. So when I look at that table, there will be one entry for each WI.

Here is the asp/sql statment I have:

Dim strSQL, copyEMPWI
strSQL = "INSERT INTO iso_employwi (pin, wi, date_added) SELECT '" & EmpCopy & "', wi, GETDATE() FROM iso_employwi " &_
"WHERE (wi IN (" & strWiList & "))"

When the asp page is run in debug mode, it shows the sql statement as:

INSERT INTO iso_employwi (pin, wi, date_added) SELECT '170', wi, GETDATE() FROM iso_employwi
WHERE (wi IN (WI8-5-003, Z05041452, Z05065054))

When the asp page is now actually ran to execute, it gives this error:
Error Type:
Microsoft OLE DB Provider for SQL Server (0x80040E14)
Invalid column name 'Z05065054'.

If things worked correctly, I would expect the table result to look like this:

PIN | WI | Date_Added
170 |WI8-5-003 | <sql date>
170 | Z05041452 | <sql date>
170 | Z05065054 | <sql date>

Anyone have any ideas on how I can fix my sql statement to correct this error? Hope my explanation makes sense.

JLM

jose1lm
Yak Posting Veteran

70 Posts

Posted - 2005-09-01 : 14:24:56
found the problem. I forgot to have the string enclose each of the "WI" in single quotes.

ie: ('WI8-5-003', 'Z05041452', 'Z05065054')

Thx anyways,

JLM
Go to Top of Page
   

- Advertisement -