Solved

syntax error - in know these records are there

Posted on 2013-02-01
7
230 Views
Last Modified: 2013-02-01
I know data values exist for this string below.  Am I doing something wrong in the syntax

select * from tblJJDP where Fiscal = 2012 and not IVPA = 'I'
0
Comment
Question by:al4629740
7 Comments
 
LVL 65

Expert Comment

by:Jim Horn
Comment Utility
Possibly, but without access to your data source it's hard to tell.

Knee-jerk reactions...

>Fiscal = 2012
this works if Fiscal is some kind of Numeric.  If it's a char then you'll need Fiscal = '2012'

>and not IVPA = 'I'
and IVPA <> 'I' would be a little cleaner
verify that you want AND instead of OR
Verify that there is capital I, and not also lowercase i records that you want in your results
0
 
LVL 65

Expert Comment

by:Jim Horn
Comment Utility
>Fiscal = 2012
Also if Fiscal is a date then Year(Fiscal) = 2012
0
 
LVL 3

Expert Comment

by:Nalinkumarbalaji
Comment Utility
Try this one

select * from tblJJDP where Fiscal ='2012' and IVPA <> 'I'

Go with jimhorn comment
0
Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

 

Author Comment

by:al4629740
Comment Utility
still nothing.

I do notice that many values in IVPA have either an 'I' or NULL
0
 
LVL 65

Accepted Solution

by:
Jim Horn earned 300 total points
Comment Utility
>many values in IVPA have either an 'I' or NULL
You'll have to handle the NULL values then, something like using COALESCE, which returns the first non-null value between the parentheses:

select *
from tblJJDP
where Fiscal = 2012 and COALESCE(IVPA, 'foo') <>  'I'
0
 
LVL 31

Assisted Solution

by:awking00
awking00 earned 200 total points
Comment Utility
Another method -
select * from tblJJdp where Fiscal = 2012
except
select * from tblJJdp where IVPA = 'I'
0
 

Author Comment

by:al4629740
Comment Utility
Thats crazy I never knew that.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Truncate vs Delete 63 87
SQL Server RDS clr assembly 4 33
Complex SQL 10 32
sql calculate averages 18 21
When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

762 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

7 Experts available now in Live!

Get 1:1 Help Now