SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Site Related Forums
 Article Discussion
 SQL SERVER Dynamic SQL Help
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

yaaadman
Starting Member

4 Posts

Posted - 06/27/2007 :  10:09:18  Show Profile  Reply with Quote
I can't get the below dynamic sql to work. I am getting this error.
Server: Msg 170, Level 15, State 1, Line 1
Line 1: Incorrect syntax near '.'.
Any Help?

DECLARE @Sql nvarchar(2000)

SET @Sql = 'SELECT stag.id,
REPLACE(stag.broker,stag.broker,''Staging'' + stag.broker ) '
SET @Sql = @Sql + 'us.cocoid, ua.UserAccountID '
SET @Sql = @Sql + '(CASE WHEN UPPER(BuySell) = ''SELL'' THEN 0 ELSE 1 END) '
SET @Sql = @Sql + 'stag.tradeDate, CONVERT(INT, REPLACE(stag.quantity,''.000'','''')) '
SET @Sql = @Sql + 'stag.symbol '
SET @Sql = @Sql + 'FROM dbo.StagingSchwab stag, Users us, UserAccounts ua '
SET @Sql = @Sql + 'WHERE stag.cusip <> '''' AND us.cocoid = ua.cocoid '
SET @Sql = @Sql + 'AND REPLACE(ua.AccountNumber,''-'','''') = stag.AccountNumber'

harsh_athalye
Flowing Fount of Yak Knowledge

India
5509 Posts

Posted - 06/27/2007 :  10:17:25  Show Profile  Visit harsh_athalye's Homepage  Click to see harsh_athalye's MSN Messenger address  Send harsh_athalye a Yahoo! Message  Reply with Quote
You are missing commas at the end of each concatenation, Dude!

SET @Sql = 'SELECT stag.id,
REPLACE(stag.broker,stag.broker,''Staging'' + stag.broker ), '
SET @Sql = @Sql + 'us.cocoid, ua.UserAccountID, '
SET @Sql = @Sql + '(CASE WHEN UPPER(BuySell) = ''SELL'' THEN 0 ELSE 1 END), '
SET @Sql = @Sql + 'stag.tradeDate, CONVERT(INT, REPLACE(stag.quantity,''.000'','''')), '
SET @Sql = @Sql + 'stag.symbol '
SET @Sql = @Sql + 'FROM dbo.StagingSchwab stag, Users us, UserAccounts ua '
SET @Sql = @Sql + 'WHERE stag.cusip <> '''' AND us.cocoid = ua.cocoid '
SET @Sql = @Sql + 'AND REPLACE(ua.AccountNumber,''-'','''') = stag.AccountNumber'

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

madhivanan
Premature Yak Congratulator

India
22754 Posts

Posted - 06/27/2007 :  10:25:46  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
Must read article
www.sommarskog.se/dynamic_sql.html

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

yaaadman
Starting Member

4 Posts

Posted - 06/27/2007 :  11:27:16  Show Profile  Reply with Quote
Thanks a bunch for all your help... It was really the missing commas
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.25 seconds. Powered By: Snitz Forums 2000