Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Help on sql statement
Message
 
 
To
02/04/2002 21:05:44
James Blackburn
Qualty Design Systems, Inc.
Kuna, Idaho, United States
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Miscellaneous
Thread ID:
00637006
Message ID:
00640220
Views:
19
This message has been marked as the solution to the initial question of the thread.
I think it can be done in one select.
select s.sortcode,
	s.descrp, s.siteno,
	sf.freqcode, sf.frequency, sf.firstfreq,
	sf.numfirstloads, sf.checkscale
from  samplefreqs sf join sortcodes s
		on sf.sortcode = s.sortcode and sf.rcode = s.rcode
where sf.brandid = @brandid and sf.rcode = @rcode
union
select s.sortcode,
	s.descrp, s.siteno,
	sf.freqcode, sf.frequency, sf.firstfreq, 	
	sf.numfirstloads, sf.checkscale
from  samplefreqs sf join sortcodes s on sf.rcode = s.rcode
where sf.brandid = @brandid and sf.rcode = @rcode and sf.sortcode = '*'
	and not exists ( 
		select * from samplefreqs sf1 
			where sf1.sortcode = s.sortcode
				and sf1.rcode = @rcode and sf.brandid = @brandid )
>Sergey
>
>I put some comments in the code.
>
>sampefreqs table - a table that says how often to pick a sample of a load based on the type of product (sortcode) that is being delived
>
>sortcodes table - a table of all the possible sortcodes available.
>
>/*
>This procedure retrieves all the possible sortcode combinations based on
>how the user has input the records in the samplefreqs table. If there is
>A "*" in a row in the sortcode column then all sortcodes in
>the sortcodes table are valid for that brand. Otherwise, only the
>sortcodes in the samplefreqs table are valid. The values declared
>below are used as the default value for all the rest of the sortcode
>records that are not in the samplefreqs table.
>
>*/
>
< snip >
--sb--
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform