473,503 Members | 1,701 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 13948

"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
5969
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
3252
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
15558
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
4065
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
3034
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
3052
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
1360
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
5083
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
5112
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
7199
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7273
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
5572
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5000
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3161
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3150
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1501
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
731
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
374
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.