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 |
|
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 ExtrapolatedFrom @ResultsFor me i need to have a extrapolated column if Extrapolated = 0 or Extrapolated = 1 other wise there no column should appearie, only MatchID,ClubID,PlayerID must visible.Is it Possible.GaneshSolutions 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 @ResultselseSelect MatchID,ClubID,PlayerID from @Results E 12°55'05.25"N 56°04'39.16" |
 |
|
|
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 |
 |
|
|
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 ExtrapolatedFrom @ResultsFor me i need to have a extrapolated column if Extrapolated = 0 or Extrapolated = 1 other wise there no column should appearie, only MatchID,ClubID,PlayerID must visible.Is it Possible.GaneshSolutions 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? |
 |
|
|
raky
Aged Yak Warrior
767 Posts |
Posted - 2008-07-23 : 11:16:48
|
| It may help you..Try thisCREATE TABLE Results ( MatchID INT IDENTITY(1,1), ClubID VARCHAR(50) , PlayerID VARCHAR(50), Extrapolated BIT )INSERT INTO RESULTSSELECT 'C1','P1',1 UNION ALLSELECT 'C1','P2',1 UNION ALLSELECT 'C2','P1',0 UNION ALLSELECT 'C3','P1', NULL--select * from ResultsDECLARE @mid INT,@sql VARCHAR(MAX),@s INTSELECT @mid = 4, @sql= ''SELECT @s = Extrapolated FROM Results WHERE matchid = @midSELECT @sql = 'select matchid,ClubID,PlayerID'IF @s in (0,1)BEGINselect @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) |
 |
|
|
|
|
|
|
|