Search the Community
Showing results for tags 'case'.
-
I would like to have this +3 apply when the paymentterm if is less than 45. So the current code is using case statement. SELECT SUM(sblPOAmount) AS totalPOAmt, case when paymentTerm = '45 Days' then DATENAME(Day, DATEADD(day, SUBSTRING(paymentTerm, 1, 2) + 3, SBLInvoiceDate)) else DATENAME(Day, DATEADD(day, SUBSTRING(paymentTerm, 1, 2) + 0, SBLInvoiceDate)) end FROM [A_Sys].[dbo].[Eventtbl] WHERE DATENAME(MONTH, DATEADD(day,SUBSTRING(paymentTerm, 1, 2)+3,SBLInvoiceDate))='June' AND DATENAME(YEAR, DATEADD(day,SUBSTRING(paymentTerm, 1, 2)+3,SBLInvoiceDate))='2017' Group By paymentTerm,SBLInvoiceDate The Sum having multiple result due to "Group By", but if i run it without Group By , it will have error message. Please help
-
class ufo { const MP_SIZE_LARGE = 600; const MP_SIZE_MEDIUM = 400; const MP_SIZE_SMALL = 250; const LARGE = 'LARGE'; const MEDIUM = 'MEDIUM'; const SMALL = 'SMALL'; public $mp_size; public function desired_width() { switch ( $this->mp_size ) { case ufo::LARGE : return ufo::MP_SIZE_LARGE; case ufo::MEDIUM : return ufo::MP_SIZE_MEDIUM; case ufo::SMALL : return ufo::MP_SIZE_SMALL; default: return 0; } } } So check out the class and function above. What should "desired width" return if mp_size is 0? It makes no sense that the value is anything but 0. Instead, it returns 600. In fact, it will return 400 if I put the "medium" case first. Why would it do that? The function returns expected values if I put strval() around the mp_size. Can someone explain that? This makes absolutely no sense to me. I can't see how the order of the cases could possibly matter, and I also can't see how any case would be "true" when 0 doesn't equal "LARGE".
-
Hi, I want to set a variable based on the contents of another variable - I think I've see CASE used for this before but not entirely sure. Basically I'm trying to tidy this up: if ($var1 = "1") { $var2 = "a" } if ($var1 = "2" ) { $var2 = "b" } if ($var1 = "3") { $var2 = "c" } Any help appreciated. Thanks.