473,609 Members | 1,874 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_M TO.ImportID, dbo.tblIMPORT_M TO.MTONo,
dbo.tblIMPORT_M TO.Rev AS New_Rev, dbo.tblMTO.Rev AS Old_Rev
FROM dbo.tblIMPORT_M TO LEFT OUTER JOIN
dbo.tblMTO ON dbo.tblIMPORT_M TO.MTONo = dbo.tblMTO.MTON o

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_r ev,0)

or in the view

CREATE VIEW view1 as
SELECT dbo.tblIMPORT_M TO.ImportID, dbo.tblIMPORT_M TO.MTONo,
ISNULL(dbo.tblI MPORT_MTO.Rev,0 ) AS New_Rev, ISNULL(dbo.tblM TO.Rev AS
Old_Rev,0)
FROM dbo.tblIMPORT_M TO LEFT OUTER JOIN
dbo.tblMTO ON dbo.tblIMPORT_M TO.MTONo = dbo.tblMTO.MTON o;

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

"Trev@Work" <no.email@pleas e> wrote in message
news:41******** *************** @news.easynet.c o.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_M TO.ImportID, dbo.tblIMPORT_M TO.MTONo,
dbo.tblIMPORT_M TO.Rev AS New_Rev, dbo.tblMTO.Rev AS Old_Rev
FROM dbo.tblIMPORT_M TO LEFT OUTER JOIN
dbo.tblMTO ON dbo.tblIMPORT_M TO.MTONo = dbo.tblMTO.MTON o

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_r ev,0)

or in the view

CREATE VIEW view1 as
SELECT dbo.tblIMPORT_M TO.ImportID, dbo.tblIMPORT_M TO.MTONo,
ISNULL(dbo.tblI MPORT_MTO.Rev,0 ) AS New_Rev, ISNULL(dbo.tblM TO.Rev AS
Old_Rev,0)
FROM dbo.tblIMPORT_M TO LEFT OUTER JOIN
dbo.tblMTO ON dbo.tblIMPORT_M TO.MTONo = dbo.tblMTO.MTON o;

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@pleas e> wrote in message
news:41******** *************** @news.easynet.c o.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_M TO.ImportID, dbo.tblIMPORT_M TO.MTONo,
dbo.tblIMPORT _MTO.Rev AS New_Rev, dbo.tblMTO.Rev AS Old_Rev
FROM dbo.tblIMPORT_M TO LEFT OUTER JOIN
dbo.tblMTO ON dbo.tblIMPORT_M TO.MTONo = dbo.tblMTO.MTON o

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_r ev,0)

or in the view

CREATE VIEW view1 as
SELECT dbo.tblIMPORT_M TO.ImportID, dbo.tblIMPORT_M TO.MTONo,
ISNULL(dbo.tb lIMPORT_MTO.Rev ,0) AS New_Rev, ISNULL(dbo.tblM TO.Rev AS
Old_Rev,0)
FROM dbo.tblIMPORT_M TO LEFT OUTER JOIN
dbo.tblMTO ON dbo.tblIMPORT_M TO.MTONo = dbo.tblMTO.MTON o;

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
5981
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
3258
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 at the cost of several seconds. i was hoping someone could give me pointers on how to optimize it. perhaps, i should break it down into smaller SPs, or create additional indices on the source table, etc. thank you in advance for your help!
6
15569
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 clause. Is this possible in a standard-conforming manner? The simple for of the query is this: SELECT * FROM <table> WHERE <column> = <value>
5
4069
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 criteria of Race, Gender and Crime Code. But the Crime Code field in the table is text, and I cannot change it. I want to use a range of crime codes, so need to convert it to an integer on-the-fly. Here's what I have in my code so far:
16
3051
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 certificate at the end of the year. I have the code working fine, except for the fact that when I want to restrict the entries to awards between certain dates, even though I can use the restriction in the query that shows the actual records, when the...
2
3061
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 DataColumn.Expression). Unfortunately, when one's a Null, apparently it makes the whole string a Null and that's what's seen in the grid. This is what I use: DataColumn col_input = new DataColumn("Input"); col_input.DataType =...
3
1369
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 THE CODE: ===== Private Sub butFind_Click()
4
5088
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() I get the following error: Error Type: ADODB.Recordset (0x800A0CC1) Item cannot be found in the collection corresponding to the requested name or ordinal.
2
5127
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 want to also filter the options by date selections or not if they wish. I added to unbound text fields to input the start and end dates and inserted them into my str Where code. It was working fine until the these were added.
0
8091
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8579
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8555
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8232
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8408
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7024
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5524
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4032
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2540
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 we have to send another system

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.