کوئری چند شرطی | بلاگ

کوئری چند شرطی

تعرفه تبلیغات در سایت

آخرین مطالب

امکانات وب

سلام دوستان و اساتید گرامی
من در حال نوشتن یه برنامه هستم که حدود 1000 تا رکورد داره که هر رکورد شامل 9 علاقه مندی است و من می خواستم یه بنویسم که با انتخاب علاقه مندی های مختلف جستجو کنه .راه های زیادی رفتم ولی به نتیجه نرسیدم .
لطفا کمک کنید
این کد هایی که من نوشتم ولی جواب ندادن
ALTER PROCEDURE dbo.serach_alaghe_mandi @barname_ghorani bit, 
@mosighi bit,
@taatr bit,
@honar_tajasomi bit,
@pajohesh_hay_farhangi_va_honari bit,
@ketab bit,
@kodak_va_nojavan bit,
@resane_digital bit,
@sheer_va_adabiyat bit
AS
select * from tbl_nazar_sanji where
(barname_ghorani=@barname_ghorani or @barname_ghorani is null) and
(mosighi=@mosighi or @mosighi is null) and
(taatr=@taatr or @taatr is null) and
(honar_tajasomi=@honar_tajasomi or @honar_tajasomi is null) and
(pajohesh_hay_farhangi_va_honari=@pajohesh_hay_far hangi_va_honari or @pajohesh_hay_farhangi_va_honari is null) and
(ketab=@ketab or @ketab is null )and
(kodak_va_nojavan=@kodak_va_nojavan or @kodak_va_nojavan is null )and
(resane_digital=@resane_digital or @resane_digital is null )and
(sheer_va_adabiyat=@sheer_va_adabiyat or @sheer_va_adabiyat is null )
RETURN

//

ALTER PROCEDURE sgh_search1 @barname_ghorani bit, 
@mosighi bit,
@taatr bit,
@honar_tajasomi bit,
@pajohesh_hay_farhangi_va_honari bit,
@ketab bit,
@kodak_va_nojavan bit,
@resane_digital bit,
@sheer_va_adabiyat bit
ASSELECT id_sabt, tell, tahsilat, barname_ghorani, mosighi, taatr, honar_tajasomi, pajohesh_hay_farhangi_va_honari, ketab, kodak_va_nojavan, resane_digital,
sheer_va_adabiyat
FROM tbl_nazar_sanji
WHERE (barname_ghorani=@barname_ghorani or @barname_ghorani is null)UNION
SELECT id_sabt, tell, tahsilat, barname_ghorani, mosighi, taatr, honar_tajasomi, pajohesh_hay_farhangi_va_honari, ketab, kodak_va_nojavan, resane_digital,
sheer_va_adabiyat
FROM tbl_nazar_sanji AS tbl_nazar_sanji_1
WHERE (mosighi=@mosighi or @mosighi is null)
UNION
SELECT id_sabt, tell, tahsilat, barname_ghorani, mosighi, taatr, honar_tajasomi, pajohesh_hay_farhangi_va_honari, ketab, kodak_va_nojavan, resane_digital,
sheer_va_adabiyat
FROM tbl_nazar_sanji AS tbl_nazar_sanji_2
WHERE (taatr=@taatr or @taatr is null)
UNION
SELECT id_sabt, tell, tahsilat, barname_ghorani, mosighi, taatr, honar_tajasomi, pajohesh_hay_farhangi_va_honari, ketab, kodak_va_nojavan, resane_digital,
sheer_va_adabiyat
FROM tbl_nazar_sanji AS tbl_nazar_sanji_2
WHERE (honar_tajasomi=@honar_tajasomi or @honar_tajasomi is null)
UNION
SELECT id_sabt, tell, tahsilat, barname_ghorani, mosighi, taatr, honar_tajasomi, pajohesh_hay_farhangi_va_honari, ketab, kodak_va_nojavan, resane_digital,
sheer_va_adabiyat
FROM tbl_nazar_sanji AS tbl_nazar_sanji_2
WHERE (pajohesh_hay_farhangi_va_honari=@pajohesh_hay_far hangi_va_honari or @pajohesh_hay_farhangi_va_honari is null)
UNION
SELECT id_sabt, tell, tahsilat, barname_ghorani, mosighi, taatr, honar_tajasomi, pajohesh_hay_farhangi_va_honari, ketab, kodak_va_nojavan, resane_digital,
sheer_va_adabiyat
FROM tbl_nazar_sanji AS tbl_nazar_sanji_2
WHERE (ketab=@ketab or @ketab is null )
UNION
SELECT id_sabt, tell, tahsilat, barname_ghorani, mosighi, taatr, honar_tajasomi, pajohesh_hay_farhangi_va_honari, ketab, kodak_va_nojavan, resane_digital,
sheer_va_adabiyat
FROM tbl_nazar_sanji AS tbl_nazar_sanji_2
WHERE (kodak_va_nojavan=@kodak_va_nojavan or @kodak_va_nojavan is null)
UNION
SELECT id_sabt, tell, tahsilat, barname_ghorani, mosighi, taatr, honar_tajasomi, pajohesh_hay_farhangi_va_honari, ketab, kodak_va_nojavan, resane_digital,
sheer_va_adabiyat
FROM tbl_nazar_sanji AS tbl_nazar_sanji_2
WHERE (resane_digital=@resane_digital or @resane_digital is null)
UNION
SELECT id_sabt, tell, tahsilat, barname_ghorani, mosighi, taatr, honar_tajasomi, pajohesh_hay_farhangi_va_honari, ketab, kodak_va_nojavan, resane_digital,
sheer_va_adabiyat
FROM tbl_nazar_sanji AS tbl_nazar_sanji_2
WHERE (sheer_va_adabiyat=@sheer_va_adabiyat or @sheer_va_adabiyat is null)RETURN

//

  try            {
SqlConnection cnn = new SqlConnection(Program.ConnectionString);
cnn.Open();
SqlDataAdapter dt = new SqlDataAdapter(@"SELECT id_sabt, tell, tahsilat, alaghe_mandi
FROM tbl_nazar_sanji
WHERE (alaghe_mandi LIKE N'%"+alaghe_mandi+"%')", cnn);
DataSet ds = new DataSet();
dt.Fill(ds, "tbl_nazar_sanji");
dgv_nazar_sanji.DataSource = ds.Tables["tbl_nazar_sanji"];
}
catch (SqlException ex)
{
MessageBox.Show(ex.Message.ToString());
}
...
نویسنده : محمد رضا جوادیان بازدید : 4 تاريخ : جمعه 20 بهمن 1396 ساعت: 22:26