Click here to Skip to main content
15,885,537 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am developing a website there are two form searchscreen and serachresultscreen in first form i select a range from two dropdown list (i.e From value1 to value 2)

range is for diamond clarity like in order respectively

FL,IF,VVS,VVS1,VVS2,SI,SI1,I1,I2
when i range query it on next form like

clarity>=FL and clarity<=VVS1
then it show result with all values between alphabet F to V (i.e FL,IF,VVS,VVS1,VV2,SI,I1,I2

please suggest me some answere

My required output is(when selected between from=FL to=VVS1) then result output value FL,IF,VVS,VVS1 only

[edit]Spurious code block removed - OriginalGriff[/edit]
Posted
Updated 24-May-13 22:05pm
v2
Comments
Amir Mahfoozi 25-May-13 5:06am    
Hi,
Here is one solution : Make a table containing two fields : one of them containing FL,IF,VVS,VVS1,VVS2,SI,SI1,I1,I2 and the other one contains order values: 1,2,3,4... . then join related tables to this table and filter the order value for the required range.

1 solution

Try this:
SQL
DECLARE @tmp TABLE(Clarity VARCHAR(30), RowNo INT)

--get all Clarities 
;WITH Clarities AS
(
    SELECT 1 AS RowNo, Clarity
    FROM YourTable
    UNION ALL
    SELECT RowNo + 1 AS RowNo, Clarity
    FROM Clarities
)
INSERT INTO @tmp (Clarity, RowNo)
SELECT Clarity, RowNo
FROM Clarities
--uncomment below line if no. of Clarities in your table is more than 100
--OPTION (MAXRECURSION 0)

--declare variables to get first and last clarity no.
DECLARE @firstClarity INT
DECLARE @lastClarity INT

--get id for the first clarity
SELECT @firstClarity = MIN(RowNo)
FROM @tmp
WHERE Clarity = 'FL' 
--get id for the last clarity
SELECT @lastClarity = MAX(RowNo)
FROM @tmp
WHERE Clarity = 'VVS1' 

--result query:
SELECT t1.Clarity
FROM YourTable AS t1 LEFT JOIN @tmp AS t2 ON t1.Clarity = t2.Clarity
WHERE t2.RowNo BETWEEN @firstClarity AND @lastClarity


In above example, i use CTE[^] to get all clarities and to add unique number for them. Please, read comment in above code.
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900