472,354 Members | 2,147 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,354 software developers and data experts.

Where to put ISNULL

I have two tables, tblMTO and tblIMPORT_MTO. If I import an entire MTO
into the import table I want to create a delta from it (i.e. leave only
the changed items). I have a view (simplified)

SELECT dbo.tblIMPORT_MTO.ImportID, dbo.tblIMPORT_MTO.MTONo,
dbo.tblIMPORT_MTO.Rev AS New_Rev, dbo.tblMTO.Rev AS Old_Rev
FROM dbo.tblIMPORT_MTO LEFT OUTER JOIN
dbo.tblMTO ON dbo.tblIMPORT_MTO.MTONo = dbo.tblMTO.MTONo

Now to get all rows where old_rev = new_rev I also want all rows where
both are null, is the best method to put ISNULL() in the view or to
select from the view using ISNULL in the criteria, e.g.

select * from view1 where ISNULL(Old_Rev,0)=ISNULL(new_rev,0)

or in the view

CREATE VIEW view1 as
SELECT dbo.tblIMPORT_MTO.ImportID, dbo.tblIMPORT_MTO.MTONo,
ISNULL(dbo.tblIMPORT_MTO.Rev,0) AS New_Rev, ISNULL(dbo.tblMTO.Rev AS
Old_Rev,0)
FROM dbo.tblIMPORT_MTO LEFT OUTER JOIN
dbo.tblMTO ON dbo.tblIMPORT_MTO.MTONo = dbo.tblMTO.MTONo;

select * from view1 where Old_Rev=new_rev;
Jul 20 '05 #1
2 13779

"Trev@Work" <no.email@please> wrote in message
news:41***********************@news.easynet.co.uk. ..
I have two tables, tblMTO and tblIMPORT_MTO. If I import an entire MTO into
the import table I want to create a delta from it (i.e. leave only the
changed items). I have a view (simplified)

SELECT dbo.tblIMPORT_MTO.ImportID, dbo.tblIMPORT_MTO.MTONo,
dbo.tblIMPORT_MTO.Rev AS New_Rev, dbo.tblMTO.Rev AS Old_Rev
FROM dbo.tblIMPORT_MTO LEFT OUTER JOIN
dbo.tblMTO ON dbo.tblIMPORT_MTO.MTONo = dbo.tblMTO.MTONo

Now to get all rows where old_rev = new_rev I also want all rows where
both are null, is the best method to put ISNULL() in the view or to select
from the view using ISNULL in the criteria, e.g.

select * from view1 where ISNULL(Old_Rev,0)=ISNULL(new_rev,0)

or in the view

CREATE VIEW view1 as
SELECT dbo.tblIMPORT_MTO.ImportID, dbo.tblIMPORT_MTO.MTONo,
ISNULL(dbo.tblIMPORT_MTO.Rev,0) AS New_Rev, ISNULL(dbo.tblMTO.Rev AS
Old_Rev,0)
FROM dbo.tblIMPORT_MTO LEFT OUTER JOIN
dbo.tblMTO ON dbo.tblIMPORT_MTO.MTONo = dbo.tblMTO.MTONo;

select * from view1 where Old_Rev=new_rev;


You could do either - putting ISNULL() in the view is more convenient if
you'll use the same query a lot, but you might find it's better to put it in
the query if that means you can use the same view for other queries more
easily. Or just create two views, of course.

Having said that, I don't really understand what you're doing - if you want
to find where old_rev is the same as new_rev, that suggests you're looking
for those rows which have the same value in both tables (although 'delta'
seems to suggest the opposite). If so, then why do you need an outer join?
This affects why dbo.tblMTO.Rev is NULL - it could either be a NULL in the
data (which you would want to see), or a NULL because there's no matching
row in dbo.tblMTO (which you wouldn't).

It's very possible that I've misunderstood what you're doing, so if this
doesn't help, I suggest you post CREATE TABLE and INSERT statements to set
up some sample data, along with the results you want to see in your view.
That way others can cut and paste into QA, and we don't have to guess about
keys, data types, NULLable columns etc.

http://www.aspfaq.com/etiquette.asp?id=5006

Simon
Jul 20 '05 #2
Simon Hayes wrote:
"Trev@Work" <no.email@please> wrote in message
news:41***********************@news.easynet.co.uk. ..
I have two tables, tblMTO and tblIMPORT_MTO. If I import an entire MTO into
the import table I want to create a delta from it (i.e. leave only the
changed items). I have a view (simplified)

SELECT dbo.tblIMPORT_MTO.ImportID, dbo.tblIMPORT_MTO.MTONo,
dbo.tblIMPORT_MTO.Rev AS New_Rev, dbo.tblMTO.Rev AS Old_Rev
FROM dbo.tblIMPORT_MTO LEFT OUTER JOIN
dbo.tblMTO ON dbo.tblIMPORT_MTO.MTONo = dbo.tblMTO.MTONo

Now to get all rows where old_rev = new_rev I also want all rows where
both are null, is the best method to put ISNULL() in the view or to select
from the view using ISNULL in the criteria, e.g.

select * from view1 where ISNULL(Old_Rev,0)=ISNULL(new_rev,0)

or in the view

CREATE VIEW view1 as
SELECT dbo.tblIMPORT_MTO.ImportID, dbo.tblIMPORT_MTO.MTONo,
ISNULL(dbo.tblIMPORT_MTO.Rev,0) AS New_Rev, ISNULL(dbo.tblMTO.Rev AS
Old_Rev,0)
FROM dbo.tblIMPORT_MTO LEFT OUTER JOIN
dbo.tblMTO ON dbo.tblIMPORT_MTO.MTONo = dbo.tblMTO.MTONo;

select * from view1 where Old_Rev=new_rev;

You could do either - putting ISNULL() in the view is more convenient if
you'll use the same query a lot, but you might find it's better to put it in
the query if that means you can use the same view for other queries more
easily. Or just create two views, of course.

Having said that, I don't really understand what you're doing - if you want
to find where old_rev is the same as new_rev, that suggests you're looking
for those rows which have the same value in both tables (although 'delta'
seems to suggest the opposite). If so, then why do you need an outer join?
This affects why dbo.tblMTO.Rev is NULL - it could either be a NULL in the
data (which you would want to see), or a NULL because there's no matching
row in dbo.tblMTO (which you wouldn't).

It's very possible that I've misunderstood what you're doing, so if this
doesn't help, I suggest you post CREATE TABLE and INSERT statements to set
up some sample data, along with the results you want to see in your view.
That way others can cut and paste into QA, and we don't have to guess about
keys, data types, NULLable columns etc.

http://www.aspfaq.com/etiquette.asp?id=5006


When I said "select" that was just an example, what I'm doing (or
wanting to do) is to delete rows that haven't changed since the last
import so I will be left with the delta. The left join is there because
the imported row may be an addition so won't exist in the main table
yet. I used Rev as an example column, in reality this should not be null
(not if the CAD people know how to use CAD <g>).

So I assume for efficiency's sake, it wouldn't matter where to put the
ISNULL(), although the view I'm creating is just for this one purpose I
shall probably keep the nulls in there JIC of any future use to make it
more flexible.
Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Chris | last post by:
I have tableA, defined as: field1 varchar2(10), field2 varchar2(10), field3 varchar2(10) I have host variables defined as: v1 pic x(10) varying v2 pic x(10) varying
0
by: Alex Vorobiev | last post by:
admittedly, this SP is probably a mess given that I am not a TSQL pro. its purpose is to, based on the arguments, do 1) paging or 2) return prev/next ids for a given record. it does the job, but...
6
by: Kevin Frey | last post by:
Hello, I have a table which contains some nullable columns. I want to write a single query, which can be prepared (ie. prepared statement), that can handle null or non-null values for the where...
5
by: Rachel Weeden | last post by:
I'm working on an ASP Web application, and am having syntax issues in a WHERE statement I'm trying to write that uses the CInt Function on a field. Basically, I want to select records using...
16
by: Dixie | last post by:
I have a problem using Dev Ashish's excellent module to concatenate the results of a field from several records into one record. I am using the code to concatenate certain awards onto a...
2
by: VMI | last post by:
In my datatable, I'm retrieving three fields from an Access table and I concatenate them into one string. Then I put this information in another datacolumn that I added to the datatable (with...
3
by: amywolfie | last post by:
I have a FIND Form with three unbound combo boxes (the cbos below). I am able to open frmFindResults, but it is pulling up ALL records, not those cited in strWhere. Help!! Thanks - HERE'S...
4
by: jimm.sander | last post by:
Hello, Problem: Im using isnull() in vbscript to determine if a field returned from a ado object call is in fact null. The problem is when I use isnull in anything other than a response.write()...
2
by: Ceebaby via AccessMonster.com | last post by:
Hi Folks I wondered if someone could point me in the right direction before I completely tear my hair out. I have a user selection form where options can be selected for a report. Users now...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made but the http to https rule only works for...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. header("Location:".$urlback); Is this the right layout the...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it so the python app could use a http request to get...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.