• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 236
  • Last Modified:

SQL View

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
CEGE
Asked:
CEGE
  • 3
  • 2
1 Solution
 
chapmandewCommented:
Im not sure I follow...is this a varchar field?  What values are you checking against?
0
 
CEGEAuthor Commented:
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
 
chapmandewCommented:
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
Improve Your Query Performance Tuning

In this FREE six-day email course, you'll learn from Janis Griffin, Database Performance Evangelist. She'll teach 12 steps that you can use to optimize your queries as much as possible and see measurable results in your work. Get started today!

 
BrandonGalderisiCommented:
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
 
chapmandewCommented:
that looks like a neat site Brandon...I'll check it out.
0
 
CEGEAuthor Commented:
Fantastic!!! That was it....very cool. thank you.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Improve Your Query Performance Tuning

In this FREE six-day email course, you'll learn from Janis Griffin, Database Performance Evangelist. She'll teach 12 steps that you can use to optimize your queries as much as possible and see measurable results in your work. Get started today!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now