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.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Proc resultset with GridView

Author  Topic 

Shilpa22
Starting Member

37 Posts

Posted - 2010-10-08 : 05:33:46
I have a storedproc..which has 2 condtions...first cond queries table 1 and 2 condition queries table 2.I am assigning that result set to grid view.columns are different in both the result sets.for example..wen first cond = true...I get col1, col2,col3
other wise col4,col5,col6.
but while assigning the results..even thoug 2 condition is true....I am getting the cols as col1,col2,col3
instead i shud get col4,5,6
y is this happening? wen i execute the proc...i get the correct cols
in DB.When I make autogeneratecols= true, that time also I am getting first cond resultset columns only. What AM I missing here. Please guide me

Thanks in Advance
Shilpa

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-10-17 : 04:51:27
are you using union or union all? if yes it will always take column names from first result set. Can i ask what you're exact requirement is?. If you're sure under any condition you'll have only single resultset out of table1 or table2 then you can return them like

SELECT col1,col2,col3,cast(null as <datatype of col4>) AS col4,cast(null as <datatype of col5>) AS col5,cast(null as <datatype of col6>) AS col6
from table1
union all
SELECT null,null,null,col4,col5,col6
from table2


etc



------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -