|
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
|
|
|
July 27th, 2003, 12:16 PM
|
Authorized User
|
|
Join Date: Jun 2003
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
July 27th, 2003, 07:19 PM
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 215
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
July 28th, 2003, 02:26 AM
|
Authorized User
|
|
Join Date: Jun 2003
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|
July 28th, 2003, 02:30 AM
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 215
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
July 28th, 2003, 06:01 AM
|
Authorized User
|
|
Join Date: Jun 2003
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
July 28th, 2003, 01:49 PM
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 839
Thanks: 0
Thanked 1 Time in 1 Post
|
|
What is the datatype of the "welcome_page.img_id" column?
Jeff Mason
Custom Apps, Inc.
www.custom-apps.com
|
July 28th, 2003, 02:02 PM
|
Authorized User
|
|
Join Date: Jun 2003
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
It's "int" (eger)
|
July 28th, 2003, 03:53 PM
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 839
Thanks: 0
Thanked 1 Time in 1 Post
|
|
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
|
July 28th, 2003, 06:21 PM
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 215
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Are you sure that the column doesn't contain a null value?
regards
David Cameron
|
July 29th, 2003, 02:30 PM
|
Authorized User
|
|
Join Date: Jun 2003
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|
|