hi all,
I have a procedure:
- ALTER Procedure [dbo].[Prc_TBMonPerfSecNBase_BlnForm](@P_Year varchar(4),@P_Month varchar(2))
- As
- Declare @Cols varchar(max),
- @Sql varchar(max)
- Select @Cols=Stuff((Select ',''''AS ' + quotename(Sec_Name)+',''''AS '+quotename(Sec_Code)
- From Tb_Section
- Where Sec_Base = 1
- For xml path('')), 1, 1, '')
- Set @Sql = 'Select Sec_Name,
- Sec_Code,'
- +@P_Year+'[???]'+
- ','
- +@P_Month+'[???]'+
- ','
- + @Cols
- + 'From Tb_Section Where Sec_Base = 0 Order by Sec_Name'
- exec (@Sql)
why?
please help me...
thanks

Shubham KumarRank #621 · 3.8K reputationPosted Feb 2, 2016, 10:41 PM EST
a h26 reputationPosted Feb 2, 2016, 11:34 PM EST
@Sql varchar(max)
Set @Cols=stuff((Select ',''''AS ' + quotename(Sec_Name)--+',''''AS '+quotename(Sec_Code)
From Tb_Section
Where Sec_Base = 1
For xml path('')), 1, 1, '');
Set @Sql = 'Select Sec_Name,'
+ @Cols
+ 'From Tb_Section Where Sec_Base = 0 Order by Sec_Name'
exec (@Sql)
Shubham KumarRank #621 · 3.8K reputationPosted Feb 2, 2016, 11:45 PM EST
+ ' as Somename From Tb_Section Where Sec_Base = 0 Order by Sec_Name'
exec (@Sql)
a h26 reputationPosted Feb 3, 2016, 12:16 AM EST
Shubham KumarRank #621 · 3.8K reputationPosted Feb 3, 2016, 12:25 AM EST
Ranjit PowarRank #553 · 4.4K reputationPosted Feb 3, 2016, 12:33 AM EST
a h26 reputationPosted Feb 3, 2016, 12:45 AM EST
a h26 reputationPosted Feb 3, 2016, 1:02 AM EST
Shubham KumarRank #621 · 3.8K reputationPosted Feb 3, 2016, 1:37 AM EST
a h26 reputationPosted Feb 3, 2016, 5:12 AM EST
a h26 reputationPosted Feb 3, 2016, 6:15 AM EST
ALTER Procedure [dbo].[test3] as
Declare @Cols varchar(max),
@Sql varchar(max)
Set @Cols=( '''''AS [2]');
print @cols
Set @sql=' select 1 as[one], ' + @Cols
exec (@Sql)
ALTER Procedure [dbo].[test3] as
Declare @Cols varchar(max),
@Sql varchar(max)
Set @Cols=(Select '''''AS [2]');
print @cols
Set @sql=' select 1 as[one], ' + @Cols
exec (@Sql)
I have image(1) above in Sql server But image for Datagridview in C#:Shubham KumarRank #621 · 3.8K reputationPosted Feb 3, 2016, 7:30 AM EST
a h26 reputationPosted Feb 4, 2016, 1:47 AM EST