Solved

SQL View

Posted on 2009-04-08
6
187 Views
Last Modified: 2012-05-06
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
Comment
Question by:CEGE
  • 3
  • 2
6 Comments
 
LVL 60

Expert Comment

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

Author Comment

by:CEGE
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

by:
chapmandew earned 500 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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
LVL 39

Expert Comment

by:BrandonGalderisi
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

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

Author Closing Comment

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

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now