Author |
Topic |
sasan.kh
Starting Member
23 Posts |
Posted - 2013-01-07 : 10:54:19
|
Hi AllI have a table named Table1 with two integer fields: ID, ID2:ID ID21 NULL2 NULL3 1I have a view of this table named ViewOfTable1:SELECT ID1, ID2, 'Ok' AS FlagFROM Table1WHERE ID2 IS NOT NULLI run the following query:SELECT Table1.ID, ViewOfTable1.FlagFROM Table1LEFT OUTER JOIN ViewOfTable1 ON Table1.ID = ViewOfTable1.ID2I expect the result to be :ID Flag1 Ok2 NULL3 NULLAnd this is what I get on my machine with SQL Server Desktop Edition installed but when I run this query in another machine with SQL Server 2000 Enterprise Edition SP4 I get:ID Flag1 Ok2 OK3 OKWhat could be the problem? |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-01-07 : 11:27:28
|
check if definition of view is same in other machine------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
nigelrivett
Master Smack Fu Yak Hacker
3385 Posts |
Posted - 2013-01-07 : 11:50:55
|
And try recompiling it.==========================================Cursors are useful if you don't know sql.SSIS can be used in a similar way.Beer is not cold and it isn't fizzy. |
|
|
sasan.kh
Starting Member
23 Posts |
Posted - 2013-01-08 : 08:25:33
|
the main problem is why 3 'Ok's are returned. There should be just one |
|
|
nigelrivett
Master Smack Fu Yak Hacker
3385 Posts |
Posted - 2013-01-08 : 09:09:49
|
Could be that the views are diffrent or the data is different.==========================================Cursors are useful if you don't know sql.SSIS can be used in a similar way.Beer is not cold and it isn't fizzy. |
|
|
sasan.kh
Starting Member
23 Posts |
Posted - 2013-01-08 : 11:53:32
|
Thanx for your reply...I am sure about the Data and the View, I can run some queries and post the results if it helps... |
|
|
nigelrivett
Master Smack Fu Yak Hacker
3385 Posts |
Posted - 2013-01-08 : 12:09:45
|
What does select * from ViewOfTable1return on each server==========================================Cursors are useful if you don't know sql.SSIS can be used in a similar way.Beer is not cold and it isn't fizzy. |
|
|
sasan.kh
Starting Member
23 Posts |
Posted - 2013-01-08 : 14:03:23
|
on server 1:Select * from Table1ID1 ID21 null2 null3 1----------------------SELECT *FROM dbo.ViewOfTable1ID1 ID2 Flag3 1 Ok----------------------SELECT *FROM dbo.Table1 LEFT OUTER JOIN dbo.ViewOfTable1 ON dbo.Table1.ID1 = dbo.ViewOfTable1.ID2ID1 ID2 ID1 ID2 Flag1 null 3 1 Ok2 null null null Ok3 1 null null Ok |
|
|
sasan.kh
Starting Member
23 Posts |
Posted - 2013-01-08 : 14:17:53
|
On server 2:-------------------------SELECT *FROM dbo.Table1ID1 ID21 null2 null3 1------------------------SELECT *FROM dbo.ViewOfTable1ID1 ID2 Flag3 1 Ok ------------------------SELECT *FROM dbo.Table1 LEFT OUTER JOIN dbo.ViewOfTable1 ON dbo.Table1.ID1 = dbo.ViewOfTable1.ID2ID1 ID2 ID1 ID2 Flag1 null 3 1 Ok2 null null null null3 1 null null null |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-01-08 : 23:35:54
|
i think issue is in definition of view ViewOfTable1 . can you post definition from both servers?you can get it bysp_helptext 'ViewofTable1'------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
sasan.kh
Starting Member
23 Posts |
Posted - 2013-01-09 : 00:58:57
|
server 1:CREATE VIEW dbo.ViewOfTable1 AS SELECT ID1, ID2, 'Ok' AS Flag FROM dbo.Table1 WHERE (ID2 IS NOT NULL)server 2:CREATE VIEW dbo.ViewOfTable1 AS SELECT ID1, ID2, 'Ok' AS Flag FROM dbo.Table1 WHERE (ID2 IS NOT NULL) |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-01-09 : 01:30:42
|
whats ANSI NULL setting on both servers?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
nigelrivett
Master Smack Fu Yak Hacker
3385 Posts |
Posted - 2013-01-09 : 03:48:54
|
I don't see how you can get a row (null, null, 'ok') from the view.You might look at the query plans to see if it doing something odd.Did you recompile the view?Try this on both serverscreate table #a (id int, id2 int)insert #a select 1, nullinsert #a select 2, nullinsert #a select 3, 1select *from #a aleft join (select *, c='ok' from #a where id2 is not null) bon a.id = b.id2==========================================Cursors are useful if you don't know sql.SSIS can be used in a similar way.Beer is not cold and it isn't fizzy. |
|
|
sasan.kh
Starting Member
23 Posts |
Posted - 2013-01-09 : 07:51:56
|
Your code returned:1 NULL 3 1 ok2 NULL NULL NULL NULL3 1 NULL NULL NULLas I expected but I can not understand the difference with my query...quote: Originally posted by nigelrivett create table #a (id int, id2 int)insert #a select 1, nullinsert #a select 2, nullinsert #a select 3, 1select *from #a aleft join (select *, c='ok' from #a where id2 is not null) bon a.id = b.id2
|
|
|
sasan.kh
Starting Member
23 Posts |
Posted - 2013-01-09 : 08:02:53
|
When I change the query to :select *from table1 aleft join (select *, c='ok' from table1 where id2 is not null) bon a.id1 = b.id2I get :1 NULL 3 1 ok2 NULL NULL NULL NULL3 1 NULL NULL NULLbut after running:select *from table1 aleft join viewOfTable1 bon a.id1 = b.id2when ViewOfTable1 is exactly equal to :(select *, c='ok' from table1 where id2 is not null)the result is :1 NULL 3 1 ok2 NULL NULL NULL ok3 1 NULL NULL ok |
|
|
sasan.kh
Starting Member
23 Posts |
Posted - 2013-01-09 : 08:09:04
|
quote: Originally posted by visakh16 whats ANSI NULL setting on both servers?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/
It is OFF in both |
|
|
nigelrivett
Master Smack Fu Yak Hacker
3385 Posts |
Posted - 2013-01-09 : 09:39:24
|
did you recompile the view?==========================================Cursors are useful if you don't know sql.SSIS can be used in a similar way.Beer is not cold and it isn't fizzy. |
|
|
sasan.kh
Starting Member
23 Posts |
Posted - 2013-01-09 : 18:02:04
|
I didn't recompile it...I will try to recompile and test |
|
|
|