احمد سامعی
یک شنبه 10 اردیبهشت 1391, 13:30 عصر
سلام
من یک کوئری به شکل زیر نوشتم. وقتی که مقدار نال پاس می کنم باید همه رکوردها بازگشت داده بشه اما فقط چند تا رو بر می بازگشت می ده و وقتی مقدار @deskId ست می کنم هیچ مقداری بازگشت داده نمی شه
select * from DocumentTB
WHERE
case when DocumentTB.customerType = 3 then COALESCE(@deskId, DocumentTB.customerId)
when DocumentTB.customerType < 2 then COALESCE(@commonId, DocumentTB.customerId)
else DocumentTB.customerId end
اینجوری هم نوشتم باز هم همونجوری
(DocumentTB.customerId =
case DocumentTB.customerType
when 0 then COALESCE(@commonId, DocumentTB.customerId)
when 1 then COALESCE(@commonId, DocumentTB.customerId)
when 2 then DocumentTB.customerId
when 3 then COALESCE(@deskId, DocumentTB.customerId)
end)
من sql server 2008 استفاده می کنم
من یک کوئری به شکل زیر نوشتم. وقتی که مقدار نال پاس می کنم باید همه رکوردها بازگشت داده بشه اما فقط چند تا رو بر می بازگشت می ده و وقتی مقدار @deskId ست می کنم هیچ مقداری بازگشت داده نمی شه
select * from DocumentTB
WHERE
case when DocumentTB.customerType = 3 then COALESCE(@deskId, DocumentTB.customerId)
when DocumentTB.customerType < 2 then COALESCE(@commonId, DocumentTB.customerId)
else DocumentTB.customerId end
اینجوری هم نوشتم باز هم همونجوری
(DocumentTB.customerId =
case DocumentTB.customerType
when 0 then COALESCE(@commonId, DocumentTB.customerId)
when 1 then COALESCE(@commonId, DocumentTB.customerId)
when 2 then DocumentTB.customerId
when 3 then COALESCE(@deskId, DocumentTB.customerId)
end)
من sql server 2008 استفاده می کنم