Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
chandan_joshi80
Starting Member
30 Posts |
Posted - 2008-06-07 : 09:02:28
|
I am creating a procedure and passing a parameter.On the basis of that parameter i want to group by in the proceduregroup by @FinancialYearI tried dynamic also but no resultCode :Declare @FinancialYear_1 [varchar](50)DECLARE @sql nvarchar(4000)set @FinancialYear_1='2006-2007'set @sql= 'select @FinancialYear_1,sum(a.Receipt) as Receipt,sum(a.Payment) as Payment from(select FinancialYear,VouicherAmt as Receipt,0 as Payment from PCMAVoucherwhere substring(VoucherMode,2,1)='+'"R"'+'union allselect FinancialYear,0,VouicherAmt from PCMAVoucherwhere substring(VoucherMode,2,1)=' +'"P"' +') agroup by ' + @FinancialYearbut it is showing errorchandan Joshi |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-06-07 : 10:25:20
|
Do you ever set @FinancialYear to a valid value? E 12°55'05.25"N 56°04'39.16" |
 |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-06-07 : 10:34:15
|
[code]DECLARE @FinancialYear NVARCHAR(50) @SQL NVARCHAR(4000)SELECT @FinancialYear = '2006-2007', @SQL = ' SELECT ' + QUOTENAME(@FinancialYear, '''') + ' AS FinancialYear, SUM(Receipt) AS Receipt, SUM(Payment) AS Payment FROM ( SELECT FinancialYear, VouicherAmt AS Receipt, 0 AS Payment FROM PCMAVoucher WHERE SUBSTRING(VoucherMode, 2, 1) = ''R'' UNION ALL SELECT FinancialYear, 0, VouicherAmt FROM PCMAVoucher WHERE SUBSTRING(VoucherMode, 2, 1) = ''P'' ) AS a GROUP BY FinancialYear 'EXEC (@SQL)[/code] E 12°55'05.25"N 56°04'39.16" |
 |
|
|
|
|
|
|