Author |
Topic |
rjhe22
Constraint Violating Yak Guru
283 Posts |
Posted - 2013-06-21 : 05:46:58
|
hihave this sql TotalReturn1Year = CASE WHERE As_of_Date > DATEADD(yy,DATEDIFF(yy,0,[Date_To]),'19000620')AND As_of_Date <= DATEADD(yy,DATEDIFF(yy,0,[Date_To]),'19000630') getting the following error Msg 102, Level 15, State 1, Line 17Incorrect syntax near '19000630'. any idea why i have these in a few places and there is no error with the others |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-06-21 : 05:50:00
|
it should be WHENTotalReturn1Year = CASE WHERE WHEN As_of_Date > DATEADD(yy,DATEDIFF(yy,0,[Date_To]),'19000620')AND As_of_Date <= DATEADD(yy,DATEDIFF(yy,0,[Date_To]),'19000630') THEN... ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
rjhe22
Constraint Violating Yak Guru
283 Posts |
Posted - 2013-06-21 : 05:56:27
|
ok thanks |
|
|
rjhe22
Constraint Violating Yak Guru
283 Posts |
Posted - 2013-06-21 : 05:57:23
|
still get the error |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-06-21 : 06:02:23
|
quote: Originally posted by rjhe22 still get the error
show the full code------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
rjhe22
Constraint Violating Yak Guru
283 Posts |
Posted - 2013-06-21 : 06:04:57
|
[code]SET QUOTED_IDENTIFIER OFFDECLARE @SqlStmt NVARCHAR(max), @WorkingDataloadFile NVARCHAR(256), @FundCode NVARCHAR(256), @DefaultDate NVARCHAR(256)SELECT @WorkingDataloadFile = ?SELECT @FundCode = ?SELECT @DefaultDate = '1900-01-01'SELECT @SQLStmt = 'UPDATE ' + @WorkingDataloadFile + ' SET TotalReturn1Year = CASE WHEN As_of_Date > DATEADD(yy,DATEDIFF(yy,0,[Date_To]),'19000620')AND As_of_Date <= DATEADD(yy,DATEDIFF(yy,0,[Date_To]),'19000630') THEN Net_Distributions_Paid_Amount ELSE 0.00 END ,TotalReturn9Months = CASE WHEN As_of_Date > DATEADD(yy,DATEDIFF(yy,0,[Date_To]),'19000630')AND As_of_Date <= DATEADD(yy,DATEDIFF(yy,0,[Date_To]),'19000930') THEN Net_Distributions_Paid_Amount ELSE 0.00 END ,TotalReturn6Months = CASE WHEN As_of_Date > DATEADD(yy,DATEDIFF(yy,0,[Date_To]),'19000930')AND As_of_Date <= DATEADD(yy,DATEDIFF(yy,0,[Date_To]),'19001231') THEN Net_Distributions_Paid_Amount ELSE 0.00 END ,TotalReturn3Months = CASE WHEN As_of_Date > DATEADD(yy,DATEDIFF(yy,0,[Date_To]),'19001231')AND As_of_Date <= DATEADD(yy,DATEDIFF(yy,0,[Date_To]),'19000331') THEN Net_Distributions_Paid_Amount ELSE 0.00 END ,TotalReturn1Month = CASE WHEN As_of_Date > DATEADD(yy,DATEDIFF(yy,0,[Date_To]),'19000331')AND As_of_Date <= DATEADD(yy,DATEDIFF(yy,0,[Date_To]),'19000619') THEN Net_Distributions_Paid_Amount ELSE 0.00 END ,TotalReturn10YearCumulative = CASE WHEN As_of_Date > DATEADD(yy,DATEDIFF(yy,0,[Date_To]),'19000620')AND As_of_Date <= DATEADD(yy,DATEDIFF(yy,0,[Date_To]),'19000630') THEN Distribution_Paid_CPU ELSE 0.00 END ,TotalReturn9YearCumulative = CASE WHEN As_of_Date > DATEADD(yy,DATEDIFF(yy,0,[Date_To]),'19000630')AND As_of_Date <= DATEADD(yy,DATEDIFF(yy,0,[Date_To]),'19000930') THEN Distribution_Paid_CPU ELSE 0.00 END ,TotalReturn6YearCumulative = CASE WHEN As_of_Date > DATEADD(yy,DATEDIFF(yy,0,[Date_To]),'19000930')AND As_of_Date <= DATEADD(yy,DATEDIFF(yy,0,[Date_To]),'19001231') THEN Distribution_Paid_CPU ELSE 0.00 END ,TotalReturn3YearCumulative = CASE WHEN As_of_Date > DATEADD(yy,DATEDIFF(yy,0,[Date_To]),'19001231')AND As_of_Date <= DATEADD(yy,DATEDIFF(yy,0,[Date_To]),'19000331') THEN Distribution_Paid_CPU ELSE 0.00 END ,TotalReturn2YearCumulative = CASE WHEN As_of_Date > DATEADD(yy,DATEDIFF(yy,0,[Date_To]),'19000331')AND As_of_Date <= DATEADD(yy,DATEDIFF(yy,0,[Date_To]),'19000619') THEN Distribution_Paid_CPU ELSE 0.00 END ,TotalReturn10YearAnnualized = CASE WHEN As_of_Date > DATEADD(yy,DATEDIFF(yy,0,[Date_To]),'19000620')AND As_of_Date <= DATEADD(yy,DATEDIFF(yy,0,[Date_To]),'19000630') THEN Reinvested_Distributions ELSE 0.00 END ,TotalReturn9YearAnnualized = CASE WHEN As_of_Date > DATEADD(yy,DATEDIFF(yy,0,[Date_To]),'19000630')AND As_of_Date <= DATEADD(yy,DATEDIFF(yy,0,[Date_To]),'19001030') THEN Reinvested_Distributions ELSE 0.00 END ,TotalReturn6YearAnnualized = CASE WHEN As_of_Date > DATEADD(yy,DATEDIFF(yy,0,[Date_To]),'19001030')AND As_of_Date <= DATEADD(yy,DATEDIFF(yy,0,[Date_To]),'19001231') THEN Reinvested_Distributions ELSE 0.00 END ,TotalReturn3YearAnnualized = CASE WHEN As_of_Date > DATEADD(yy,DATEDIFF(yy,0,[Date_To]),'19001231')AND As_of_Date <= DATEADD(yy,DATEDIFF(yy,0,[Date_To]),'19000331') THEN Reinvested_Distributions ELSE 0.00 END ,TotalReturn2YearAnnualized = CASE WHEN As_of_Date > DATEADD(yy,DATEDIFF(yy,0,[Date_To]),'19000331')AND As_of_Date <= DATEADD(yy,DATEDIFF(yy,0,[Date_To]),'19000619') THEN Reinvested_Distributions ELSE 0.00 END '+ "WHERE SSB_Fund_Num = '" + @FundCode + "'"EXECUTE (@SQLStmt) SELECT @SQLStmt = "UPDATE " + @WorkingDataloadFile + ' SET NAVIncludingShadowPriceCalcDate = CASE WHEN DATEDIFF("dd",Date_To,Reinvest_Date) > -1 THEN Reinvest_Date ELSE ' + "'" + @DefaultDate + "'" + " END "+ "WHERE SSB_Fund_Num = '" + @FundCode + "'"EXECUTE (@SQLStmt) SET QUOTED_IDENTIFIER ONGO[/code]only happens on first one very strange |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-06-21 : 06:16:24
|
why do you need dynamic sql here? why tablename come as a parameter?Anyways if you want to use it inside dynamic string you should have '' around all date values like ..SELECT @SQLStmt = 'UPDATE ' + @WorkingDataloadFile + ' SET TotalReturn1Year = CASE WHEN As_of_Date > DATEADD(yy,DATEDIFF(yy,0,[Date_To]),''19000620'')AND As_of_Date <= DATEADD(yy,DATEDIFF(yy,0,[Date_To]),''19000630'') THEN Net_Distributions_Paid_Amount ELSE 0.00 END ... similarly in all the other placesalso you may be better off using sp_executesql over EXEC for executing dynamic stringI'm still not convinced on use of dynamic sql and making tablename a parameter. perhaps you could give us some overview if you want us to help you out with an alternative.------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
|
rjhe22
Constraint Violating Yak Guru
283 Posts |
Posted - 2013-06-21 : 06:17:26
|
its part of an ssis packages so has to be will try that thanks |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-06-21 : 06:20:10
|
quote: Originally posted by rjhe22 its part of an ssis packages so has to be will try that thanks
in that why not use a variable inside SSIS with an expression to form the query using your dynamic tablename and then use SQLSourceType as variable in execute sql task to execute query from variable?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
rjhe22
Constraint Violating Yak Guru
283 Posts |
Posted - 2013-06-21 : 06:23:04
|
ya think so but not sure i didnt do the code for this i was just asked to update it. i have not worked with ssis packages that much yet |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
|
rjhe22
Constraint Violating Yak Guru
283 Posts |
Posted - 2013-06-21 : 06:29:23
|
thanks will look into it now and see what i can do with it |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-06-21 : 06:34:34
|
welcome------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
rjhe22
Constraint Violating Yak Guru
283 Posts |
Posted - 2013-06-21 : 09:56:38
|
tried every possible way with dates but does not seem to work.tried "19000303" '19000303' "1900-03-03" '1900-03-03' still getting that error |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-06-21 : 10:26:46
|
modify like below and checkSET QUOTED_IDENTIFIER OFFDECLARE @SqlStmt NVARCHAR(max), @WorkingDataloadFile NVARCHAR(256), @FundCode NVARCHAR(256), @DefaultDate NVARCHAR(256)SELECT @WorkingDataloadFile = ?SELECT @FundCode = ?SELECT @DefaultDate = '1900-01-01'SELECT @SQLStmt = 'UPDATE ' + @WorkingDataloadFile + ' SET TotalReturn1Year = CASE WHEN As_of_Date > DATEADD(yy,DATEDIFF(yy,0,[Date_To]),''19000620'')AND As_of_Date <= DATEADD(yy,DATEDIFF(yy,0,[Date_To]),''19000630'') THEN Net_Distributions_Paid_Amount ELSE 0.00 END ,TotalReturn9Months = CASE WHEN As_of_Date > DATEADD(yy,DATEDIFF(yy,0,[Date_To]),''19000630'')AND As_of_Date <= DATEADD(yy,DATEDIFF(yy,0,[Date_To]),''19000930'') THEN Net_Distributions_Paid_Amount ELSE 0.00 END ,TotalReturn6Months = CASE WHEN As_of_Date > DATEADD(yy,DATEDIFF(yy,0,[Date_To]),''19000930'')AND As_of_Date <= DATEADD(yy,DATEDIFF(yy,0,[Date_To]),''19001231'') THEN Net_Distributions_Paid_Amount ELSE 0.00 END ,TotalReturn3Months = CASE WHEN As_of_Date > DATEADD(yy,DATEDIFF(yy,0,[Date_To]),''19001231'')AND As_of_Date <= DATEADD(yy,DATEDIFF(yy,0,[Date_To]),''19000331'') THEN Net_Distributions_Paid_Amount ELSE 0.00 END ,TotalReturn1Month = CASE WHEN As_of_Date > DATEADD(yy,DATEDIFF(yy,0,[Date_To]),''19000331'')AND As_of_Date <= DATEADD(yy,DATEDIFF(yy,0,[Date_To]),''19000619'') THEN Net_Distributions_Paid_Amount ELSE 0.00 END ,TotalReturn10YearCumulative = CASE WHEN As_of_Date > DATEADD(yy,DATEDIFF(yy,0,[Date_To]),''19000620'')AND As_of_Date <= DATEADD(yy,DATEDIFF(yy,0,[Date_To]),''19000630'') THEN Distribution_Paid_CPU ELSE 0.00 END ,TotalReturn9YearCumulative = CASE WHEN As_of_Date > DATEADD(yy,DATEDIFF(yy,0,[Date_To]),''19000630'')AND As_of_Date <= DATEADD(yy,DATEDIFF(yy,0,[Date_To]),''19000930'') THEN Distribution_Paid_CPU ELSE 0.00 END ,TotalReturn6YearCumulative = CASE WHEN As_of_Date > DATEADD(yy,DATEDIFF(yy,0,[Date_To]),''19000930'')AND As_of_Date <= DATEADD(yy,DATEDIFF(yy,0,[Date_To]),''19001231'') THEN Distribution_Paid_CPU ELSE 0.00 END ,TotalReturn3YearCumulative = CASE WHEN As_of_Date > DATEADD(yy,DATEDIFF(yy,0,[Date_To]),''19001231'')AND As_of_Date <= DATEADD(yy,DATEDIFF(yy,0,[Date_To]),''19000331'') THEN Distribution_Paid_CPU ELSE 0.00 END ,TotalReturn2YearCumulative = CASE WHEN As_of_Date > DATEADD(yy,DATEDIFF(yy,0,[Date_To]),''19000331'')AND As_of_Date <= DATEADD(yy,DATEDIFF(yy,0,[Date_To]),''19000619'') THEN Distribution_Paid_CPU ELSE 0.00 END ,TotalReturn10YearAnnualized = CASE WHEN As_of_Date > DATEADD(yy,DATEDIFF(yy,0,[Date_To]),''19000620'')AND As_of_Date <= DATEADD(yy,DATEDIFF(yy,0,[Date_To]),''19000630'') THEN Reinvested_Distributions ELSE 0.00 END ,TotalReturn9YearAnnualized = CASE WHEN As_of_Date > DATEADD(yy,DATEDIFF(yy,0,[Date_To]),''19000630'')AND As_of_Date <= DATEADD(yy,DATEDIFF(yy,0,[Date_To]),''19001030'') THEN Reinvested_Distributions ELSE 0.00 END ,TotalReturn6YearAnnualized = CASE WHEN As_of_Date > DATEADD(yy,DATEDIFF(yy,0,[Date_To]),''19001030'')AND As_of_Date <= DATEADD(yy,DATEDIFF(yy,0,[Date_To]),''19001231'') THEN Reinvested_Distributions ELSE 0.00 END ,TotalReturn3YearAnnualized = CASE WHEN As_of_Date > DATEADD(yy,DATEDIFF(yy,0,[Date_To]),''19001231'')AND As_of_Date <= DATEADD(yy,DATEDIFF(yy,0,[Date_To]),''19000331'') THEN Reinvested_Distributions ELSE 0.00 END ,TotalReturn2YearAnnualized = CASE WHEN As_of_Date > DATEADD(yy,DATEDIFF(yy,0,[Date_To]),''19000331'')AND As_of_Date <= DATEADD(yy,DATEDIFF(yy,0,[Date_To]),''19000619'') THEN Reinvested_Distributions ELSE 0.00 END '+ "WHERE SSB_Fund_Num = '" + @FundCode + "'"EXECUTE (@SQLStmt) SELECT @SQLStmt = "UPDATE " + @WorkingDataloadFile + ' SET NAVIncludingShadowPriceCalcDate = CASE WHEN DATEDIFF("dd",Date_To,Reinvest_Date) > -1 THEN Reinvest_Date ELSE ' + "'" + @DefaultDate + "'" + " END "+ "WHERE SSB_Fund_Num = '" + @FundCode + "'"EXECUTE (@SQLStmt) SET QUOTED_IDENTIFIER ONGO ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
|
|
|