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)
 Help me..

Author  Topic 

ganeshkumar08
Posting Yak Master

187 Posts

Posted - 2008-07-23 : 08:58:40
Hello,

Can i know whether there is an option in Sql Server to control to display the column.

For Ex:

Select MatchID,ClubID,PlayerID,
Case When Extrapolated = 0 or Extrapolated = 1 Then 'Yes' Else '' End As Extrapolated
From @Results

For me i need to have a extrapolated column if Extrapolated = 0 or Extrapolated = 1 other wise there no column should appear
ie, only MatchID,ClubID,PlayerID must visible.

Is it Possible.

Ganesh

Solutions are easy. Understanding the problem, now, that's the hard part

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-07-23 : 09:15:51
Yes. Use IF statement.

IF EXISTS (SELECT * FROM @Results WHERE Extrapolated = 1)
Select MatchID,ClubID,PlayerID,Extrapolated from @Results
else
Select MatchID,ClubID,PlayerID from @Results


E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

ganeshkumar08
Posting Yak Master

187 Posts

Posted - 2008-07-23 : 09:43:29
Thanks For your response, I already done like this i thought that there is any option to control in select statement itself.


Solutions are easy. Understanding the problem, now, that's the hard part
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-07-23 : 09:46:56
quote:
Originally posted by ganeshkumar08

Hello,

Can i know whether there is an option in Sql Server to control to display the column.

For Ex:

Select MatchID,ClubID,PlayerID,
Case When Extrapolated = 0 or Extrapolated = 1 Then 'Yes' Else '' End As Extrapolated
From @Results

For me i need to have a extrapolated column if Extrapolated = 0 or Extrapolated = 1 other wise there no column should appear
ie, only MatchID,ClubID,PlayerID must visible.

Is it Possible.

Ganesh

Solutions are easy. Understanding the problem, now, that's the hard part


if its for display that you want to conditionally hide a column, you can still use the above select and do the hiding/unhiding of column by altering the visibility property at your front end. what's the front end you're using?
Go to Top of Page

raky
Aged Yak Warrior

767 Posts

Posted - 2008-07-23 : 11:16:48
It may help you..Try this

CREATE TABLE Results ( MatchID INT IDENTITY(1,1), ClubID VARCHAR(50) , PlayerID VARCHAR(50), Extrapolated BIT )

INSERT INTO RESULTS
SELECT 'C1','P1',1 UNION ALL
SELECT 'C1','P2',1 UNION ALL
SELECT 'C2','P1',0 UNION ALL
SELECT 'C3','P1', NULL

--select * from Results


DECLARE @mid INT,@sql VARCHAR(MAX),@s INT
SELECT @mid = 4, @sql= ''
SELECT @s = Extrapolated FROM Results WHERE matchid = @mid

SELECT @sql = 'select matchid,ClubID,PlayerID'
IF @s in (0,1)
BEGIN
select @sql = @sql+',case when Extrapolated = ''0'' or Extrapolated = ''1'' then ''Yes'' end as ''Extrapolated'''
end
select @sql = @sql+ ' from Results where matchid = '+ cast(@mid as varchar(20))

print(@sql)
exec (@sql)
Go to Top of Page
   

- Advertisement -