I want to get number of CenterMeeting between give two date on that case

Tags: sql sql-server
Question!
case when @mode='TwoDays'
then CenterMeetingDay between datepart(dw,GETDATE()-1) and DATEPART(DW,GETDATE()+1) 
end CenterMeetingDay


Answers

In SQL Server, you cannot simply put a boolean comparison as the when clause.

So, include the condition in the when and be explicit about the return values:

(case when @mode = 'TwoDays' and
           CenterMeetingDay between datepart(dw, GETDATE() - 1) and DATEPART(DW, GETDATE() + 1) 
      then 1 else 0
 end) as CenterMeetingDay

In a where clause, you can do:

where ( (@mode = 'TwoDays') and CenterMeetingDay between datepart(dw, GETDATE() - 1) and DATEPART(DW, GETDATE() + 1)) or
      ( (@mode <> 'TwoDays' . . . )

or:

where (case when @mode = 'TwoDays' and
                 CenterMeetingDay between datepart(dw, GETDATE() - 1) and DATEPART(DW, GETDATE() + 1) 
            then 1 else 0
       end) = 1


Here is this code that i wrote for a project..the values outside for loop ( "WSDL Name" and "Tags" are the column header and list will contain values to be inserted). It will generate test.csv

import java.io.FileWriter;
import java.io.IOException;

public class genCSV
{
   public static void main(String [] args)
   {
       generateCsvFile("c:\\test.csv"); 
   }

   private static void generateCsvFile(String sFileName)
   {
    try
    {
        FileWriter writer = new FileWriter(sFileName);

    writer.append("WSDLName");
    writer.append("Tags");
    writer.append('\n');

   for(int i=0;i<list.size();i++){
       writer.append(list.getKey);
        writer.append(list.getValueForKey);
        writer.append('\n');
   }

    //generate whatever data you want

    writer.flush();
    writer.close();
}
catch(IOException e)
{
     e.printStackTrace();
} 
}
}
By : phoenix


There may be a chance of string value in the column RVU.MA. Try out with the below query to find out such descrepancies.

   SELECT *
   FROM RVU
   WHERE ISNUMERIC (RVU.MA)!=1


This video can help you solving your question :)
By: admin