dbTalk Databases Forums  

Creating a 'View'

microsoft.public.sqlserver.mseq microsoft.public.sqlserver.mseq


Discuss Creating a 'View' in the microsoft.public.sqlserver.mseq forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Micheal
 
Posts: n/a

Default Creating a 'View' - 08-06-2003 , 11:11 AM






I want to create a 'view' but have a condition on a column based on another
column. Basically, I want to do this:

CREATE VIEW MyView
AS
SELECT [id] AS dept_id,
[name] AS dept_name,
url WHEN STATUS = 'ACTIVE'
FROM department
WHERE event_sharing = 'on'


What I want to do is only display the URL field when the Status = 'Active',
and if Status <> 'Acitve' I want to return a null/blank URL field.



Reply With Quote
  #2  
Old   
Anith Sen
 
Posts: n/a

Default Re: Creating a 'View' - 08-06-2003 , 12:28 PM






You can use a CASE expression like:

SELECT id, name,
CASE status WHEN 'Active THEN url END AS url
FROM dpt
WHERE ... ;

--
- Anith
( Please reply to newsgroups only )



Reply With Quote
  #3  
Old   
Micheal
 
Posts: n/a

Default Re: Creating a 'View' - 08-06-2003 , 12:33 PM



Thank you ... that is exacting what I was looking for


"Anith Sen" <anith (AT) bizdatasolutions (DOT) com> wrote

Quote:
You can use a CASE expression like:

SELECT id, name,
CASE status WHEN 'Active THEN url END AS url
FROM dpt
WHERE ... ;

--
- Anith
( Please reply to newsgroups only )





Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.