By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,985 Members | 1,861 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,985 IT Pros & Developers. It's quick & easy.

SQL question??

P: 29
Hi everyone
Is there any way to make INSERT statement more general by placing a variable as a parameter for VALUE word?
In other words I need to use the following statement instead of the later on.

String vval=”xx,yy”;
Sql= INSERT INTO “tablename” VALUES (vval);

The original statement is:

Sql= INSERT INTO “tablename” VALUES (xx,yy);

Please help.
Many thanks in advance.
Dec 7 '06 #1
Share this Question
Share on Google+
4 Replies


Expert 100+
P: 534
This should work, but remember that string values are typically enclosed in the single quotes (Integer types are not)
So you may need to tweak your code a little.
Dec 7 '06 #2

P: 29
This should work, but remember that string values are typically enclosed in the single quotes (Integer types are not)
So you may need to tweak your code a little.
thanks 4 ur help, but it doesn't work. the following error message appears:Column count doesn't match value count at row 1. it considered as a single value not two values

plz help
cheers
Dec 8 '06 #3

Expert 100+
P: 534
I tried it with a different scripting language (did not have PHP environment available at the moment)
and it worked fine for me:
Expand|Select|Wrap|Line Numbers
  1. String vval=”'xx', 'yy'”;
Did you make sure your string values are enclosed in single-quotes?
Dec 8 '06 #4

Expert 100+
P: 534
Actually it does not look that you're using PHP either... what is the language and API you're using to communicate with the database?
Dec 8 '06 #5

Post your reply

Sign in to post your reply or Sign up for a free account.