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...

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.