October 29, 2009 at 12:52 pm
Hello Experts,
Iโm trying to write a simple T-SQL statement but having error which Iโm not able to understand at all. SQL is keep complying and saying
---------------------------------------------------------
Msg 102, Level 15, State 1, Line 1
Incorrect syntax near ','.
---------------------------------------------------------
Here is my code
-----------------------------------------------------
declare @AD_TransactionErrorAuditID varchar(30),
@AD_TransactionErrorAuditSeqNum varchar(30),
@AD_ErrorCode varchar(10),
@AD_ErrorMessage varchar(40),
@AD_Fetch_Data varchar(250)
select @AD_TransactionErrorAuditID = 'TransactionErrorAuditID'
select @AD_TransactionErrorAuditSeqNum = 'TransactionErrorAuditSequentialNumber'
select @AD_ErrorCode = 'ErrorCode'
select @AD_ErrorMessage = 'ErrorMessage'
select @AD_Fetch_Data = +@AD_TransactionErrorAuditID+ ', '
+@AD_TransactionErrorAuditSeqNum+ ', '
+@AD_ErrorCode+ ', '
+@AD_ErrorMessage
EXEC (@AD_Fetch_Data)
GO
----------------------------------------------------
Can anybody see what am I doing wrong?
Thanks a lot in advance.
October 29, 2009 at 1:00 pm
Change your exec command to a print command. You're telling it to execute something that isn't an SQL command.
- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
October 29, 2009 at 1:07 pm
From the first look, I cant understand what you trying to do here?
EXEC (@AD_Fetch_Data) ----- What do you want to execute?
@AD_Fetch_Data is going to store this value "TransactionErrorAuditID, TransactionErrorAuditSequentia, ErrorCode, ErrorMessage"
what will you execute it to?
Updated:
Well I started to reply and was caught in a conversation and could not reply in time, mean while
GSquared has mentioned what you need to do
Blog -- LearnSQLWithBru
Join on Facebook Page Facebook.comLearnSQLWithBru
Twitter -- BruMedishetty
October 29, 2009 at 1:32 pm
Thanks for you input guys. Okay I'm trying to understand in's and out's and found a very interesting exmaple as follows. This can explain you even better If you don't understand What I'm trying to do.
October 29, 2009 at 1:37 pm
Thanks SSCertifiable for you suggestion. Full points to you. It worked. Also I hope for those who don't understand what I'm doing they need to work on their clearance level.
October 29, 2009 at 1:44 pm
So here is my code if still people donโt understand what I am tying to do. The only catch is I changes @AD_TransactionErrorAuditSeqNum varchar(40) from varchar(30). This is another way to write SQL Statement. AND IT EXECUTE TOO.
---------------------------------------------------------
Here is my code
-----------------------------------------------------
declare @AD_TransactionErrorAuditID varchar(30),
@AD_TransactionErrorAuditSeqNum varchar(40),
@AD_ErrorCode varchar(10),
@AD_ErrorMessage varchar(40),
@AD_Fetch_Data varchar(250)
select @AD_TransactionErrorAuditID = 'TransactionErrorAuditID'
select @AD_TransactionErrorAuditSeqNum = 'TransactionErrorAuditSequentialNumber'
select @AD_ErrorCode = 'ErrorCode'
select @AD_ErrorMessage = 'ErrorMessage'
select @AD_Fetch_Data = +@AD_TransactionErrorAuditID+ ', '
+@AD_TransactionErrorAuditSeqNum+ ', '
+@AD_ErrorCode+ ', '
+@AD_ErrorMessage
EXEC (@AD_Fetch_Data)
GO
----------------------------------------------------
October 29, 2009 at 1:44 pm
Not sure what you mean by "clearance level", but glad I could help out.
It's pretty standard, when working with dynamic SQL, to have a print command so you can review and test the resulting string, before you execute it. Adopt that as a standard practice, and it'll help.
- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
October 29, 2009 at 1:50 pm
Thanks again SSCertifiable. It will be my rule from now to use print. This is first time I'm using SQL Server that's why tying to understand it as much & as deeply as I can. Thanks again for your input
October 29, 2009 at 1:54 pm
Thanks SSCertifiable for you suggestion. Full points to you. It worked. Also I hope for those who don't understand what I'm doing they need to work on their clearance level.
Speaking about Clearance level, First you need to know that you have not posted what you wanted to achieve with your SQL Statement. Without which it is not understandable what you are trying to do.
And also about Clearance level, I don't know what do you know but it is obvious that you are not clear about something such as this "Thanks SSCertifiable" It is GSquared who helped not SSCertifiable ๐
Blog -- LearnSQLWithBru
Join on Facebook Page Facebook.comLearnSQLWithBru
Twitter -- BruMedishetty
October 29, 2009 at 1:59 pm
Bru Medishetty (10/29/2009)
Thanks SSCertifiable for you suggestion. Full points to you. It worked. Also I hope for those who don't understand what I'm doing they need to work on their clearance level.
....
And also about Clearance level, I don't know what do you know but it is obvious that you are not clear about something such as this "Thanks SSCertifiable" It is GSquared who helped not SSCertifiable ๐
Don't worry about it. I'm used to that.
- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
October 29, 2009 at 1:59 pm
mr_adeelalisyed (10/29/2009)
So here is my code if still people donโt understand what I am tying to do. The only catch is I changes @AD_TransactionErrorAuditSeqNum varchar(40) from varchar(30). This is another way to write SQL Statement. AND IT EXECUTE TOO.---------------------------------------------------------
Here is my code
-----------------------------------------------------
declare @AD_TransactionErrorAuditID varchar(30),
@AD_TransactionErrorAuditSeqNum varchar(40),
@AD_ErrorCode varchar(10),
@AD_ErrorMessage varchar(40),
@AD_Fetch_Data varchar(250)
select @AD_TransactionErrorAuditID = 'TransactionErrorAuditID'
select @AD_TransactionErrorAuditSeqNum = 'TransactionErrorAuditSequentialNumber'
select @AD_ErrorCode = 'ErrorCode'
select @AD_ErrorMessage = 'ErrorMessage'
select @AD_Fetch_Data = +@AD_TransactionErrorAuditID+ ', '
+@AD_TransactionErrorAuditSeqNum+ ', '
+@AD_ErrorCode+ ', '
+@AD_ErrorMessage
EXEC (@AD_Fetch_Data)
GO
----------------------------------------------------
Nope, still confused as the above code when cut and paste into SSMS fails. A print (@AD_Fetch_Data) simply returns this :
TransactionErrorAuditID, TransactionErrorAuditSequentialNumber, ErrorCode, ErrorMessage
October 29, 2009 at 2:00 pm
He's trying to build a select statement, Lynn. Just not communicating it as clearly as we'd like, but that happens.
- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
October 29, 2009 at 2:23 pm
I sorta figured that, but what he has posted just doesn't execute. ๐
October 29, 2009 at 10:20 pm
Hi mr_adeelalisyed,
The reference posted by you in
gives a slight hint of issue that you might be facing.
I think you are trying to execute
TransactionErrorAuditID, TransactionErrorAuditSequentia, ErrorCode, ErrorMessage
But it is not a valid SQL Statement.
According to the link, you should add ' SELECT ' at the start of the @AD_Fetch_Data variable and ' From ValidTableName ' at the end of @AD_Fetch_Data variable (as done in the example + ' FROM authors'
). By adding these two, the statement will become valid executable statement and you will receive no error.
Viewing 14 posts - 1 through 13 (of 13 total)
You must be logged in to reply to this topic. Login to reply