Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 sql statement

Author  Topic 

lamujerdetuhermano10
Yak Posting Veteran

75 Posts

Posted - 2008-08-25 : 13:06:03
can u improve this statement?

FROM vInventoryLineItem v
JOIN [Global].[InventoryAilmentLink] [IA]
ON v.InventoryID = IA.InventoryID
JOIN [Global].[AILMENT] [AIL]
ON IA.AilmentID = AIL.AilmentID
JOIN [Global].[InventorySpeciesLink] ISL
ON v.[InventoryID] = [ISL].[InventoryID]

WHERE
(v.idMinAge < @daysOld or v.idMinAge is null )
AND (v.idMaxAge > @daysOld or v.idMaxAge is null)
AND v.idStartDate < @now
AND (v.idEndDate > @now or v.idEndDate is null)
AND [AIL].[AilmentId] = @ailmentID
AND isl.[SpeciesID] = @speciesID
AND ((@genderCode = 'M' AND ISL.IsForMale = 1)
OR (@genderCode = 'F' AND ISL.IsForFemale = 1)
OR (@genderCode = 'MN' AND ISL.IsForNeutered = 1)
OR (@genderCode = 'FS' AND ISL.IsForSpayed = 1)
OR (@genderCode = 'UN'))
AND v.idCountryCode = @countryCode
AND (v.pcCountryCode = @countryCode OR v.PcCountryCode is null)
ORDER BY [IA].[ListOrderNumber]

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2008-08-25 : 13:11:12
Only try to improve this already perfect query if you are an expert! I'm not an expert, so I'd probably start with adding a SELECT clause.

Jim
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-08-25 : 13:34:25
quote:

Msg 156, Level 15, State 1, Line 1
Incorrect syntax near the keyword 'FROM'.




Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2008-08-25 : 13:34:45
ISL.IsForNeutered this takes the cake

and you forgot to say please.

_______________________________________________
Causing trouble since 1980
Blog: http://weblogs.sqlteam.com/mladenp
Speed up SSMS development: www.ssmstoolspack.com <- version 1.0 out!
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-08-26 : 02:01:53
I don't think "u" can do this. Maybe "h" can?



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

blindman
Master Smack Fu Yak Hacker

2365 Posts

Posted - 2008-08-28 : 16:49:07
quote:
Originally posted by lamujerdetuhermano10

can u improve this statement?

Yes. Try: "Can you improve this statement?". It has superior spelling and capitalization.

Boycotted Beijing Olympics 2008
Go to Top of Page
   

- Advertisement -