Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 how to return columns like select
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Starting Member

Saudi Arabia
35 Posts

Posted - 04/28/2013 :  17:49:37  Show Profile  Reply with Quote
when create store procedure to use last code (Posted - 04/25/2013 : 03:30:39 )
and call Sp by c# reports no return columns like select statement

how to return columns ?

alter proc SP_Report_atend_lecture

DECLARE @Pivot VARCHAR(4000)  = '', 
@sql VARCHAR(MAX) = '', 
SET @Pivot = STUFF( (SELECT ',[' + CAST( lesson_number AS VARCHAR) +']'
				FROM View_1
				GROUP BY lesson_number
				FOR XML PATH('')), 1, 1 , '');
SET @PivotCols = @PivotCols + REPLACE( @Pivot, ',', ', ''0'' ), COALESCE( ') + ', ''0'')'

SET @sql = @sql + ' 
SELECT ID_student, ' + @PivotCols +
 FROM view_1
 where stae=''no'' or stae=''yes''
 ) AS P
 Max(stae) FOR lesson_number IN ( ' + @Pivot + ' ) 
) AS pv ';

EXEC (@sql)


please help me
to create report in c#
for office
???? ???? ???????

James K
Flowing Fount of Yak Knowledge

3873 Posts

Posted - 04/28/2013 :  18:14:16  Show Profile  Reply with Quote
It depends on how you are invoking the stored procedure from C#. What framework are you using to connect to SQL? If you are using ADO.Net you should use ExecuteReader or Fill ( of a data adapter) rather than ExecuteScalar or ExecuteNonquery.
Go to Top of Page

Starting Member

Saudi Arabia
35 Posts

Posted - 04/29/2013 :  00:02:28  Show Profile  Reply with Quote
i use ADO.Net
fill data set but no column
i use wizard to create data set then create report then drop table and chose data-source
look at image
1- image chose data-source for report

2- test dataset

3- report no columns when call dataset

please help me
for office
???? ???? ???????
Go to Top of Page

Very Important crosS Applying yaK Herder

52326 Posts

Posted - 04/29/2013 :  00:45:59  Show Profile  Reply with Quote
thats because the sp uses a dynamic pivot and hence it cant determine metadat at designtime. I think better approach would be to put placeholders for all columns so that metadata will remain static and based on whether it has values or not you can write report expression for the same

SQL Server MVP
Go to Top of Page
  Previous Topic Topic Next 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.02 seconds. Powered By: Snitz Forums 2000