Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Revised: New to Dynamic SQL need help with syntax error 3

Status
Not open for further replies.

avid1741

Technical User
May 30, 2002
10
US
I keep getting the syntax error:Incorrect syntax near the keyword 'From'. I assume it is referring to the last line where a FROM exist. Any help is appreciated

Declare @InPutDate as VarChar(255)
SET @InPutDate = '_'+ CAST(Datepart(month,GetDate()) as VarChar(2)) + '_W'
+ CAST(Datepart(Month,GetDate())as VarChar(2)) + CAST(Datepart(Day,GetDate()) as Varchar(2))+
'_' + CAST(Right(Datepart(Year,Getdate()),2)as VarChar(2))+ '_Test'

Declare @OutPutDate as VarChar(255)
SET @OutPutDate = '_'+ CAST(Datepart(month,GetDate()) as VarChar(2)) + '_W'
+ CAST(Datepart(Month,GetDate())as VarChar(2)) + CAST(Datepart(Day,GetDate()) as Varchar(2))+
'_' + CAST(Right(Datepart(Year,Getdate()),2)as VarChar(2))+ '_Test'

---Source Data tables Distribution Names
Declare @DistNamesSrcTable as VarChar(255)
Set @DistNamesSrcTable = 'Distribution_Names'+ @InPutDate

-----Output Table
Declare @AgentTble as VarChar (255)
Set @AgentTble = 'Distribution_Names'+ @OutPutDate --Distribution_Names output table

Declare @StrSQL as VarChar(5000)

--Here @AgentTble = Distribution_Names
--Declare @StrSQL as VarChar(5000)
--Set @StrSql = N'Select distinct number as agent_code INTO '+ @AgentTble + ' From ' + @AgentSrcTable +
--' Create index ix_1 on '+ @AgentTble + '(Company_id,contract,account)'

Set @StrSql = N'Delete * + ' From '+ @DistNamesSrcTable'
+ 'where number = '58' and code ='400''
 
It's in your delete statement. Take out the * and it would be syntactically correct.

Set @StrSql = N'Delete From '+ @DistNamesSrcTable'
+ 'where number = '58' and code ='400''


Tim
 
Well you don't need the "* from" in the delete statement and you have an extra quote or two.


Set @StrSql = N'Delete ' + @DistNamesSrcTable
+ N' where number = 58 and code = ''400'''

(Do these need to be unicode?
Assuming number is numeric and code character.



======================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
 
Posted too quickly, I missed some quotes too

Set @StrSql = N'Delete From '+ @DistNamesSrcTable + 'where number = ''58'' and code =''400'''

Tim
 
He's got more trouble then that. Avid1741, build the statement a little at a time and keep printing it out with
Select @StrSql.
It's better to teach a man to fish, then feed him. :)
-Karl
 
Actually looking at this I would be concerned about the design of this system rather than the code.
Seems to be allocating tables to days etc.



======================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top