masysh
چهارشنبه 13 اردیبهشت 1385, 16:42 عصر
جلوگیری از نمایش سطرهایی که مقادیر مربوط به ماهها خالی می باشند.
با این کوئری در فیلد نام و کد تمام کد ونامهایی که در جدول موجود باشد را نمایش می دهد .و عدم وجود مقدار برای ستون های دیگر را نادیده می گیرد.یعنی اگر مقادیر تمام ستونهای دیگر خالی باشد و مقدار دهی نشده باشند یا در شرط صدق نکنند باز نام را نمایش می دهد.
اگر بخواهم فقط نامهایی را نمایش دهد که حداقل یکی از ماههای آن دارای مقدار باشد چه باید بکنم؟
این کد را برای تمام 12 ماه نوشته ام.
select distinct personnel_code,personnel_name,
(select case when sum(personnel_prize)>=@fb then sum(personnel_prize)+@f
else sum(personnel_prize) end as f
from table1 as tfarvardin
where (P_date between @f1 and @f2 ) and (personnel_code=table1.personnel_code)
having (@f=@f11) and (@fb=@fb11)) as 'farvardin'
(select case when sum(personnel_prize)>=@ob then sum(personnel_prize)+@o
else sum(personnel_prize) end as o
from table1 as tordibehesht
where (P_date between @o1 and @o2) and (personnel_code=table1.personnel_code)
having (@o=@o11) and (@ob=@ob11)) as 'ordibehesht'
from table1
where sex=@sex
order by personnel_code
با این کوئری در فیلد نام و کد تمام کد ونامهایی که در جدول موجود باشد را نمایش می دهد .و عدم وجود مقدار برای ستون های دیگر را نادیده می گیرد.یعنی اگر مقادیر تمام ستونهای دیگر خالی باشد و مقدار دهی نشده باشند یا در شرط صدق نکنند باز نام را نمایش می دهد.
اگر بخواهم فقط نامهایی را نمایش دهد که حداقل یکی از ماههای آن دارای مقدار باشد چه باید بکنم؟
این کد را برای تمام 12 ماه نوشته ام.
select distinct personnel_code,personnel_name,
(select case when sum(personnel_prize)>=@fb then sum(personnel_prize)+@f
else sum(personnel_prize) end as f
from table1 as tfarvardin
where (P_date between @f1 and @f2 ) and (personnel_code=table1.personnel_code)
having (@f=@f11) and (@fb=@fb11)) as 'farvardin'
(select case when sum(personnel_prize)>=@ob then sum(personnel_prize)+@o
else sum(personnel_prize) end as o
from table1 as tordibehesht
where (P_date between @o1 and @o2) and (personnel_code=table1.personnel_code)
having (@o=@o11) and (@ob=@ob11)) as 'ordibehesht'
from table1
where sex=@sex
order by personnel_code