troubleshooting Question

Syntax error converting the varchar value 'NULL' to a column of data type int.

Avatar of ube100
ube100Flag for United Kingdom of Great Britain and Northern Ireland asked on
Microsoft SQL ServerC++
8 Comments1 Solution1226 ViewsLast Modified:
Hi,

I'm updating a table in sql server from a front end written in C++. This some thing like this:

                                                  sprintf(sSqlQuery,
                  "UPDATE %s set "
                  "date_rec = '%s',"
                  "tpc = '%s',"
                  "cpc = '%s',"
                  "acquisition_strategy_code = '%s',"
                  "title = %d, "
                  "first_name = '%s',"
                  "middle_initials = '%s'"
                                                   " WHERE Id = %ld ",
                  CARDAPPLICATIONS_TABLE,
                  lDateRec,
                  tpc,
                  cpc,
                  acquisition_strategy_code,
                  title,
                  first_name,
                  middle_initials,
                  lRecordId
                  );      
When I execute this statement I get's the following error:  Syntax error converting the varchar value 'NULL' to a column of data type int.
Say for the title I got null passed in but in the table that is defined as integer so database throwing the above error. This is only a part of the sql string but I got really hughe sql string so I want to  convert all those values with 'NULL' to NULL then the database will accept this as a NULL keyword rather than as NULL string.
Can smoe one advice me please.

ube100
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 8 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 8 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros