Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server ASP
|
SQL Server ASP Discussions about ASP programming with Microsoft's SQL Server. For more ASP forums, see the ASP forum category.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server ASP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 27th, 2003, 12:16 PM
Authorized User
 
Join Date: Jun 2003
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
Default COMPLEX QUERY PROBLEM

Hello all

Bellow you see a rather complex query which I run against SQL Server 2000 against my ASP pages.

SELECT welcome_page.title, welcome_page.body, welcome_page.displ_date, welcome_page.img_id, welcome_page.pos, welcome_page.border, welcome_page.caption, welcome_page.url, welcome_page.snd_id, welcome_page.embed, welcome_page.vid_id, users_imgs.img_file, users_imgs.img_width, users_imgs.img_height, users_imgs.img_alt, users_sounds.snd_file, users_sounds.snd_name, users_vids.vid_file, users_vids.vid_name FROM users_vids RIGHT JOIN (users_sounds RIGHT JOIN (users_imgs RIGHT JOIN welcome_page ON users_imgs.img_id = welcome_page.img_id) ON users_sounds.snd_id = welcome_page.snd_id) ON users_vids.vid_id = welcome_page.vid_id where welcome_page.site_id = @siteid

It does not "give me" back the value of "welcome_page.img_id" field. It returns it null. When i execute the same query directly through the Query Analyzer of SQL Server, it sends back all values as it should.

When I execute it against an Access db (through my ASP page), it also works fine. The problem appears only when it runs against SQL Server.

One more detail: If I add the "users_imgs.img_id" field it gives me its value fine, but it send blank the value of "welcome_page.snd_id" field this time.

Strange. Can anybody explain this?

Thanks in advance

Nick
 
Old July 27th, 2003, 07:19 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 215
Thanks: 0
Thanked 0 Times in 0 Posts
Default

It is clear from your code that you consider that carrige returns are evil and should be avoided at all costs.

I've cleaned up the code a little and turned it into a more normal join syntax. I'm honestly not sure how your original query would be interpreted by SQL Server. Put simply Access can't read correctly formatted SQL-92 queries. SQL Server can. Anyway, see where this gets you.
Code:
SELECT welcome_page.title, welcome_page.body, welcome_page.displ_date,
    welcome_page.img_id, welcome_page.pos, welcome_page.border,
    welcome_page.caption, welcome_page.url, welcome_page.snd_id,
    welcome_page.embed, welcome_page.vid_id, users_imgs.img_file,
    users_imgs.img_width, users_imgs.img_height, users_imgs.img_alt,
    users_sounds.snd_file, users_sounds.snd_name, users_vids.vid_file,
    users_vids.vid_name
FROM user_imgs
    INNER JOIN welcome_page ON
    users_imgs.img_id = welcome_page.img_id
    INNER JOIN user_sounds ON
    users_sounds.snd_id = welcome_page.snd_id
    INNER JOIN users_vids ON
    users_vids.vid_id = welcome_page.vid_id
WHERE welcome_page.site_id = @siteid
regards
David Cameron
 
Old July 28th, 2003, 02:26 AM
Authorized User
 
Join Date: Jun 2003
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for cleaning my code. As you can see I have RIGHT joins because I want to have recordsets even if some tables dont return values.
 
Old July 28th, 2003, 02:30 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 215
Thanks: 0
Thanked 0 Times in 0 Posts
Default

In that case use OUTER joins:

Code:
SELECT welcome_page.title, welcome_page.body, welcome_page.displ_date,
    welcome_page.img_id, welcome_page.pos, welcome_page.border,
    welcome_page.caption, welcome_page.url, welcome_page.snd_id,
    welcome_page.embed, welcome_page.vid_id, users_imgs.img_file,
    users_imgs.img_width, users_imgs.img_height, users_imgs.img_alt,
    users_sounds.snd_file, users_sounds.snd_name, users_vids.vid_file,
    users_vids.vid_name
FROM welcome_page
    LEFT OUTER JOIN users_imgs ON
    users_imgs.img_id = welcome_page.img_id
    LEFT OUTER JOIN user_sounds ON
    users_sounds.snd_id = welcome_page.snd_id
    LEFT OUTER JOIN users_vids ON
    users_vids.vid_id = welcome_page.vid_id
WHERE welcome_page.site_id = @siteid
regards
David Cameron
 
Old July 28th, 2003, 06:01 AM
Authorized User
 
Join Date: Jun 2003
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Always the same result. I execute your query in Query analyzer and gives me back all data as it should.

The same query in my ASP page does NOT give me the "welcome_page.img_id" field. Everything else but that.

Unbelievable....

Nick
 
Old July 28th, 2003, 01:49 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 839
Thanks: 0
Thanked 1 Time in 1 Post
Default

What is the datatype of the "welcome_page.img_id" column?

Jeff Mason
Custom Apps, Inc.
www.custom-apps.com
 
Old July 28th, 2003, 02:02 PM
Authorized User
 
Join Date: Jun 2003
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
Default

It's "int" (eger)
 
Old July 28th, 2003, 03:53 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 839
Thanks: 0
Thanked 1 Time in 1 Post
Default

Quote:
quote:Originally posted by nikosdra
 Always the same result. I execute your query in Query analyzer and gives me back all data as it should.

The same query in my ASP page does NOT give me the "welcome_page.img_id" field. Everything else but that.

Unbelievable....

Nick
No offense meant, but I find this hard to believe. Something else is going on here. Are you saying that the resultset returned from the query simply does not include one of the columns (in particular the 4th) in the SELECT statement?

And yet the outer join referring to the same column:
Code:
 ... on users_imgs.img_id = welcome_page.img_id
works?

Perhaps you mean instead that its returned value is NULL, rather than it not being given back to you? That would be my guess, and I guess that is because you have an OUTER JOIN, and there is no match on img_id thus setting the corresponding column in the resultset to NULL, as OUTER JOINs do...

Jeff Mason
Custom Apps, Inc.
www.custom-apps.com
 
Old July 28th, 2003, 06:21 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 215
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Are you sure that the column doesn't contain a null value?

regards
David Cameron
 
Old July 29th, 2003, 02:30 PM
Authorized User
 
Join Date: Jun 2003
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I am positive. I know it sounds strange (it did also to me).

I execute exactly the same query, and I see the value "17" in the field "welcome_page.img_id". The same query in my ASP page gives me all other fields. The "welcome_page.img_id" contains NULL. When i response.write it, I see nohing.

I was afraid you would find it strange too...

Dont know what to do

Nick





Similar Threads
Thread Thread Starter Forum Replies Last Post
complex query g_vamsi_krish SQL Language 3 February 27th, 2006 10:48 AM
Help need with designing this complex query method Access 2 July 1st, 2005 05:29 AM
query too complex [email protected] Access 3 August 28th, 2003 09:01 AM
COMPLEX QUERY PROBLEM nikosdra Classic ASP Databases 2 July 28th, 2003 02:13 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.