tdenny
asked on
Insert into SQL table
Hell Experts,
I'm having a little difficulty doing something I've done many times before. I, currently inserting into a SQL database with 4 fields. To of them can be null and two can't. The ICWAEmpID is a number and the other three are text fields. Below is my SQL and below that is the error I get when I don't put a value into one or both of the not required fields (which can be null). Any ideas?
My code:
<cfquery name="InsertICWA" datasource="ddssprojdev" dbtype="ODBC">
INSERT INTO ICWA (Salco, ICWANO, BudgetNo, ICWAEmpID)
VALUES ('#FORM.Salco#','#FORM.ICW ANO#', '#FORM.BudgetNo#', #FORM.SelectOwner#);
</cfquery>
Error Diagnostic Information
ODBC Error Code = 37000 (Syntax error or access violation)
[Microsoft][ODBC SQL Server Driver][SQL Server]Line 2: Incorrect syntax near ')'.
SQL = "INSERT INTO ICWA (Salco, ICWANO, BudgetNo, ICWAEmpID) VALUES ('333333', '11111', '', )"
Data Source = "DDSSPROJDEV"
The error occurred while processing an element with a general identifier of (CFQUERY), occupying document position (53:3) to (53:68) in the template file I:\WEBSITES\DDSSPM2\UPDATE \ADDICWA_A PP.CFM.
I'm having a little difficulty doing something I've done many times before. I, currently inserting into a SQL database with 4 fields. To of them can be null and two can't. The ICWAEmpID is a number and the other three are text fields. Below is my SQL and below that is the error I get when I don't put a value into one or both of the not required fields (which can be null). Any ideas?
My code:
<cfquery name="InsertICWA" datasource="ddssprojdev" dbtype="ODBC">
INSERT INTO ICWA (Salco, ICWANO, BudgetNo, ICWAEmpID)
VALUES ('#FORM.Salco#','#FORM.ICW
</cfquery>
Error Diagnostic Information
ODBC Error Code = 37000 (Syntax error or access violation)
[Microsoft][ODBC SQL Server Driver][SQL Server]Line 2: Incorrect syntax near ')'.
SQL = "INSERT INTO ICWA (Salco, ICWANO, BudgetNo, ICWAEmpID) VALUES ('333333', '11111', '', )"
Data Source = "DDSSPROJDEV"
The error occurred while processing an element with a general identifier of (CFQUERY), occupying document position (53:3) to (53:68) in the template file I:\WEBSITES\DDSSPM2\UPDATE
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
if the query gets too big, I would suggest creating a stored procedure for inserting new rows. And make all the fields that allow null values optional parameters.
Then you don't need to do the whole query building just use CFStoredProc tag.
also, this approach is probably a better way to manage larger inserts
Thanx for the "A"
CJ
Then you don't need to do the whole query building just use CFStoredProc tag.
also, this approach is probably a better way to manage larger inserts
Thanx for the "A"
CJ
ASKER
CJ,
Thanks as always for your response. I thought there might be some sort of isNull requirement for my SQL statement. I am sure your suggestions will work. Your suggestion is certainly better than running two separate queries based on whether or not the field is used. I will do the same for both of those fields. I can't wait until I get to the really big table that this application will be inserting recdords into.
Many thanks
TD
Thanks as always for your response. I thought there might be some sort of isNull requirement for my SQL statement. I am sure your suggestions will work. Your suggestion is certainly better than running two separate queries based on whether or not the field is used. I will do the same for both of those fields. I can't wait until I get to the really big table that this application will be inserting recdords into.
Many thanks
TD
ASKER
Thanks as always for your response. I thought there might be some sort of isNull requirement for my SQL statement. I am sure your suggestions will work. Your suggestion is certainly better than running two separate queries based on whether or not the field is used. I will do the same for both of those fields. I can't wait until I get to the really big table that this application will be inserting recdords into.
Many thanks
TD