January 11, 2012 at 11:55 am
Hi,
Getting a syntax error on the following..
INSERT INTO @TEMPTABLE(TAG_NAME,TAG_DATA)
SELECT TAG_NAME = 'CUST_AGE', TAG_DATA = (SELECT FLOOR(DATEDIFF(day, BDate, CURRENT_TIMESTAMP) / 365.25))FROM client
WHERE Client.OID =@CLIENT_OID);
any help would be great..
Thanks
Joe
January 11, 2012 at 12:04 pm
jbalbo (1/11/2012)
Hi,Getting a syntax error on the following..
INSERT INTO @TEMPTABLE(TAG_NAME,TAG_DATA)
SELECT TAG_NAME = 'CUST_AGE', TAG_DATA = (SELECT FLOOR(DATEDIFF(day, BDate, CURRENT_TIMESTAMP) / 365.25))FROM client
WHERE Client.OID =@CLIENT_OID);
any help would be great..
Thanks
Joe
Not really a need to do a sub-select query:
INSERT INTO @TEMPTABLE(TAG_NAME,TAG_DATA)
SELECT 'CUST_AGE', FLOOR(DATEDIFF(day, BDate, GETDATE()) / 365.25)
FROM client
WHERE OID =@CLIENT_OID;
January 11, 2012 at 12:14 pm
thanks that works great...
hate to be a pain I really am new, can u explain why that is, just so I know?
Thanks
January 11, 2012 at 12:23 pm
jbalbo (1/11/2012)
thanks that works great...hate to be a pain I really am new, can u explain why that is, just so I know?
Thanks
lol I am no expert either, any even the best of the best will never claim to be. Let me try, but if it is not a good description hopefully one of the better posters will join in and give me a hand
--The first thing is that you already declared the order in which data will be inserted into the table.
--So no need to declaratively state what the value is for each column.
--(originally you had TAG_NAME='CUST_AGE', etc, which isn't necessary)
INSERT INTO @TEMPTABLE(TAG_NAME,TAG_DATA)
--Next, when inserting data you can INSERT specific values or from tables like a regular SELECT statement
SELECT 'CUST_AGE', FLOOR(DATEDIFF(day, BDate, GETDATE()) / 365.25)
FROM client
--To see how this works remove your where clause
--If you did not have the where clause below, it would insert a row into @TEMPTABLE
--for every BDate value in client table
WHERE OID =@CLIENT_OID;
January 11, 2012 at 12:40 pm
thats a good explaination..
Im putting it on my Fridge!!
January 13, 2012 at 6:10 am
jbalbo (1/11/2012)
Hi,Getting a syntax error on the following..
INSERT INTO @TEMPTABLE(TAG_NAME,TAG_DATA)
SELECT TAG_NAME = 'CUST_AGE',
TAG_DATA = (SELECT FLOOR(DATEDIFF(day, BDate, CURRENT_TIMESTAMP) / 365.25))
FROM client
WHERE Client.OID =@CLIENT_OID);
To answer your original question as to why you got the Syntax error to begin with.. Count your parenthesis. You should have one left for each right. At the very end of your code, you have an extra right.
January 13, 2012 at 8:37 am
WOW i NEVER PICKED THAT UP!!
January 13, 2012 at 8:37 am
Wow never picked it up!!
January 13, 2012 at 9:14 am
jbalbo (1/13/2012)
Wow never picked it up!!
It's probably the most common sql server mistake ever made and everyone, even the experts, make it constantly. Just remember: If everything else looks correct, count the parens.
January 13, 2012 at 9:32 am
thanks..
I got a new one Im tottaly confused about stay tuned!!! lol
Viewing 10 posts - 1 through 9 (of 9 total)
You must be logged in to reply to this topic. Login to reply