Welcome to dbFreaks.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

need help on this sql

 
   Database Help (Home) -> Programming RSS
Next:  Import data  
Author Message
Jeff

External


Since: Mar 07, 2007
Posts: 29



(Msg. 1) Posted: Tue Apr 07, 2009 1:26 pm
Post subject: need help on this sql
Archived from groups: microsoft>public>sqlserver>programming (more info?)

hi

sql server 2005

select top 9 p.Id, p.Thumbnail, p.RegDate, p.RegBy, a.Title, a.Category
from Picture as p
inner join Advert as a on p.advert = a.Id
inner join Category as t on a.Category = t.Id
where a.Approved = 1 and p.Thumbnail = 1 and t.MainType = 2
order by newid();

this sql returns no rows, I wonder what I do wrong here..

The category table contain hierarchy data, so I added a MainType to that
table so I quikly could filter out rows accosiated with a specific
category..

The Advert table has 1 row, it's Category value is 5, in the table Category
the Id of row where maintype is 5 is 2 - hence I thought the second join
should work

any suggestions?

 >> Stay informed about: need help on this sql 
Back to top
Login to vote
William Lipp

External


Since: May 16, 2004
Posts: 2



(Msg. 2) Posted: Tue Apr 07, 2009 1:26 pm
Post subject: Re: need help on this sql [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

General debugging approach:

strip it down until it produces some output, then add things back in.

What happens if you drop the "where" and "order" clauses?

If still no output, start dropping the inner joins (may need to change
request to "*" during the debugging.)

If you get output, put the where conditions back one at a time.


In my experience, you'll usually find a particular clause that turns
off all output. Examine it closely and you'll usually find a bug.

Good luck!




On Tue, 7 Apr 2009 17:26:36 +0200, "Jeff"
wrote:

>hi
>
>sql server 2005
>
>select top 9 p.Id, p.Thumbnail, p.RegDate, p.RegBy, a.Title, a.Category
>from Picture as p
> inner join Advert as a on p.advert = a.Id
> inner join Category as t on a.Category = t.Id
>where a.Approved = 1 and p.Thumbnail = 1 and t.MainType = 2
>order by newid();
>
>this sql returns no rows, I wonder what I do wrong here..
>
>The category table contain hierarchy data, so I added a MainType to that
>table so I quikly could filter out rows accosiated with a specific
>category..
>
>The Advert table has 1 row, it's Category value is 5, in the table Category
>the Id of row where maintype is 5 is 2 - hence I thought the second join
>should work
>
>any suggestions?
>

 >> Stay informed about: need help on this sql 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
need help with query - I want to sum the records in a table (u) which have 'P.M.' in a field value and test against a fixed limit something to the effect of : case when SUM(substring(u.sTime,1,4)='P.M.') <= 64 Then .... except it should work ...

Next?? - I have a field stored as NTEXT(16). I need to replace some of the content in this field. I know the replace function doesnt work. I see there is UPDATETEXT - is this the ONLY way to do it ?? 'cos it looks quite complicated? thanks, Justin

How can I get the resultset from a stored procedure - I have a stored procedure which will output a table. How can I use a sql statement to get the result of the sp? Thanks a lot

Audit V2 - I am looking to write a SQL script that will show me for each table, in all the databases on a server, which users / groups have access. In addition, I want to break the access into whether it is SELECT, UPDATE, INSERT or DELETE permissions. Is this..

Detecting an existence of local temporary table - Hi, I create a temporary table. for example: <font color=purple> ; create table #t1 (ID_T1 integer)</font> Next I would like to detect If the table already exists: exec sp_table #t1 if @@ROWCOUNT > 0 <font color=purple>&...
   Database Help (Home) -> Programming All times are: Pacific Time (US & Canada) (change)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]