Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
Solved

# SQL View

Posted on 2009-04-08
Medium Priority
228 Views
Hello:

This is my query;
SELECT     TOP 100 PERCENT dbo.vw_empresa_info.Cliente, dbo.vw_empresa_info.Comercial, ISNULL(dbo.vw_info_citas4wk.ONDATEA, '01/01/01')
AS Citas4wkChk
FROM         dbo.vw_info_citas4wk RIGHT OUTER JOIN
dbo.vw_empresa_info ON dbo.vw_info_citas4wk.Cliente = dbo.vw_empresa_info.Cliente AND
dbo.vw_info_citas4wk.Comercial = dbo.vw_empresa_info.Comercial

The problem is that I would like "Citas4wkChk" to be N, and if not, Y. How can I do this?

thanks,
Joseph
0
Question by:CEGE
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 3
• 2

LVL 60

Expert Comment

ID: 24097647
Im not sure I follow...is this a varchar field?  What values are you checking against?
0

LVL 1

Author Comment

ID: 24097766
sorry.
Cliente      Comercial      Citas4wkChk
1+1 STUDIO      NATALIA      01/01/2001
25RANAS      VALONSO      01/01/2001
2ÈME      NATALIA      01/01/2001
3DDB      TELEMKT      01/01/2001

The Last column is a datetieme field, and the others are varchar. and I would like perhaps another field that is "Yes" or "No", if the value in the last column is = 01/01/2001.
0

LVL 60

Accepted Solution

chapmandew earned 2000 total points
ID: 24097786
I gotcha...and if there is no value, you want it to be Y?  This will say "yes" if the value is 1/1/1, no if it is not.  If you need it swapped, just switch them around.

SELECT     TOP 100 PERCENT dbo.vw_empresa_info.Cliente, dbo.vw_empresa_info.Comercial,
case when ISNULL(dbo.vw_info_citas4wk.ONDATEA, '01/01/01')  = '01/01/01' THEN 'Yes' Else 'no' end
AS Citas4wkChk
FROM         dbo.vw_info_citas4wk RIGHT OUTER JOIN
dbo.vw_empresa_info ON dbo.vw_info_citas4wk.Cliente = dbo.vw_empresa_info.Cliente AND
dbo.vw_info_citas4wk.Comercial = dbo.vw_empresa_info.Comercial
0

LVL 39

Expert Comment

ID: 24097948
FYI:

Your top 100 percent won't actually serve a purpose.  If you are planning on doing a top 100 PERCENT so that you can order, it won't actually order.

Here's an article I wrote on the topic that explains why:
http://sqlservernation.com/blogs/brandongalderisi/archive/2009/03/15/when-ordering-in-a-view-doesn-t-work.aspx
0

LVL 60

Expert Comment

ID: 24098160
that looks like a neat site Brandon...I'll check it out.
0

LVL 1

Author Closing Comment

ID: 31568054
Fantastic!!! That was it....very cool. thank you.
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Lotus Notes has been used since a very long time as an e-mail client and is very popular because of it's unmatched security. In this article we are going to learn about  RRV Bucket corruption and understand various methods to Fix "RRV Bucket Corrupt…
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
###### Suggested Courses
Course of the Month12 days, 2 hours left to enroll