Click here to Skip to main content
15,920,217 members
Home / Discussions / Database
   

Database

 
GeneralRe: Try the update statement outside the Stored Proc Pin
enipla16-Jun-09 7:46
enipla16-Jun-09 7:46 
GeneralGood to hear Pin
David Mujica16-Jun-09 8:51
David Mujica16-Jun-09 8:51 
Questionadvance search query result? Pin
kripa2115-Jun-09 21:37
kripa2115-Jun-09 21:37 
AnswerRe: advance search query result? Pin
Niladri_Biswas17-Jun-09 20:47
Niladri_Biswas17-Jun-09 20:47 
GeneralRe: advance search query result? Pin
kripa2117-Jun-09 22:25
kripa2117-Jun-09 22:25 
AnswerRe: advance search query result? [modified] Pin
Niladri_Biswas25-Jun-09 3:02
Niladri_Biswas25-Jun-09 3:02 
GeneralRe: advance search query result? Pin
kripa2125-Jun-09 22:41
kripa2125-Jun-09 22:41 
GeneralRe: advance search query result? [modified] Pin
Niladri_Biswas27-Jun-09 19:11
Niladri_Biswas27-Jun-09 19:11 
Hi Kripa, sorry for answering late.

I was extremely busy with my project work. That's the only reason I answered late to your first question.

Anyway, here is the answer

For Case I & II

If user is searching car, which having amminities 2 & 3, he should get result as '1,2,5,6'

If user is searching car, which having amminities 1 & 2, he should get result as '1,2,3,6'


Solution 1:

SELECT CarCode
FROM tblCarAmnesty
WHERE AmmCode in (1,2) 
GROUP BY CarCode
HAVING COUNT(*) = 2


Solution 2


SELECT A.CarCode 
FROM tblCarAmnesty A, tblCarAmnesty B
WHERE A.CarCode = B.CarCode 
  AND A.AmmCode = 1
  AND B.AmmCode = 2


--------------------------------------------------------------------------
For Case III

If user is searching car, which having amminities 1,2,3, he should get result as '1,2,6'

Solution 1:

SELECT CarCode
FROM tblCarAmnesty
WHERE AmmCode in (1,2,3) 
GROUP BY CarCode
HAVING COUNT(*) = 3


Solution 2

SELECT A.CarCode 
FROM tblCarAmnesty A, tblCarAmnesty B,tblCarAmnesty C
WHERE 
	    A.CarCode = B.CarCode 
	AND B.CarCode = C.CarCode
  
		AND A.AmmCode = 1
		AND B.AmmCode = 2
		AND C.AmmCode = 3


N.B.~ As you can generalized that the count must match the number of AmmCode you are looking for for the Solution I category.

So what I suggest is that, make the Count of Ammcode as dynamic(i.e. a variable) as well as the parameter in the IN clause.

For Solution II category, I suggest better you make a dynamic SQL Query.

Hope this helps.
Smile | :)

Niladri Biswas

modified on Sunday, June 28, 2009 1:19 AM

GeneralRe: advance search query result? Pin
kripa2128-Jun-09 20:39
kripa2128-Jun-09 20:39 
GeneralRe: advance search query result? Pin
Niladri_Biswas28-Jun-09 23:24
Niladri_Biswas28-Jun-09 23:24 
QuestionHow to Clear record very fastly ( use alitle script ) in SQL server 2005? Pin
LTMKH15-Jun-09 19:34
LTMKH15-Jun-09 19:34 
Answer[Message Deleted] Pin
kripa2115-Jun-09 22:59
kripa2115-Jun-09 22:59 
QuestionRe: How to Clear record very fastly ( use alitle script ) in SQL server 2005? Pin
LTMKH15-Jun-09 23:57
LTMKH15-Jun-09 23:57 
AnswerRe: How to Clear record very fastly ( use alitle script ) in SQL server 2005? Pin
Isaac Gordon15-Jun-09 23:45
Isaac Gordon15-Jun-09 23:45 
QuestionRe: How to Clear record very fastly ( use alitle script ) in SQL server 2005? Pin
LTMKH16-Jun-09 0:19
LTMKH16-Jun-09 0:19 
AnswerRe: How to Clear record very fastly ( use alitle script ) in SQL server 2005? Pin
Vimalsoft(Pty) Ltd16-Jun-09 22:47
professionalVimalsoft(Pty) Ltd16-Jun-09 22:47 
AnswerRe: How to Clear record very fastly ( use alitle script ) in SQL server 2005? Pin
Niladri_Biswas25-Jun-09 5:32
Niladri_Biswas25-Jun-09 5:32 
Questionauthentication databse Pin
jainiraj15-Jun-09 6:04
jainiraj15-Jun-09 6:04 
AnswerRe: authentication databse Pin
Aman786Singh17-Jun-09 3:17
Aman786Singh17-Jun-09 3:17 
GeneralRe: authentication databse Pin
jainiraj18-Jun-09 4:43
jainiraj18-Jun-09 4:43 
QuestionProblem while accessing the committed data + sql server 2005 Pin
Pankaj Garg15-Jun-09 2:39
Pankaj Garg15-Jun-09 2:39 
AnswerRe: Problem while accessing the committed data + sql server 2005 Pin
himanshu256115-Jun-09 2:52
himanshu256115-Jun-09 2:52 
GeneralRe: Problem while accessing the committed data + sql server 2005 Pin
Pankaj Garg15-Jun-09 3:18
Pankaj Garg15-Jun-09 3:18 
QuestionIP restriction Error in SQL Server 2005 Pin
Aman786Singh15-Jun-09 1:00
Aman786Singh15-Jun-09 1:00 
QuestionRe: IP restriction Error in SQL Server 2005 Pin
Eddy Vluggen15-Jun-09 1:35
professionalEddy Vluggen15-Jun-09 1:35 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.