0

Hi Im still quite new when using MS SQL but I have a pretty good understanding of it.
-I am using Crystal Reports to retrieve and manipulate data from my database.
-I am creating small tables for certain data.
-This data is selected from a constantly updating table. So i use the WHERE datatime BETWEEN some date AND some date.

Now here is where I think I must use an IF statement or a CASE. The data that I am retrieving can sometimes have errors and thus the system was not operating during this day. So what I want to do is increase the day by 1 each time that shows up.

Can I use an IF statement to determine if a certain value "E" is in a certain row?

IF (SELECT FLOATTABLE.STATUS FROM FLOATTABLE WHERE FLOATTABLE.DATEANDTIME BETWEEN CONVERT(DATETIME, (CONVERT(CHAR(8), GETDATE()-DATEPART(D,CONVERT(DATETIME, (CONVERT(CHAR(8), GETDATE(), 112))))-1, 112)))  
                                 AND DATEADD(MINUTE, 10, CONVERT(DATETIME, (CONVERT(CHAR(8), GETDATE()-DATEPART(D,CONVERT(DATETIME, (CONVERT(CHAR(8), GETDATE(), 112))))-1, 112)))) AND tagIndex=26 = 'E')
BEGIN ...code...
2
Contributors
1
Reply
3
Views
7 Years
Discussion Span
Last Post by tesuji
0

MS SQL server also supports if and case statements within select. Your statement is syntactically incorrect (and much to complicated, too, to clarify such a problem). In principle if-else (there is no "then") on MS SQL server should look like:

if (select only_one_column from your_table where...) = 'E'
  begin
  /* contains 'E' 
     if you are interested in the 'E' of 'Espania' 
     you would write LIKE '%E%' instead of = 'E' 

     Here you can do further selects, for example: */

     select a, b, c from ... where ...
  end
else
  begin
  /* does not contain 'E' */

end

I myself prefer case statement for it acts like a function what is able to return a value.

-- tesu

Edited by tesuji: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.