Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 CASE Clause containg exists

Author  Topic 

barnabeck
Posting Yak Master

236 Posts

Posted - 2010-07-02 : 04:33:54
I'm setting up a calendar where SQL data is passed through ASP using a Repeater. In order to assign the data to its position in the calendar, I build up some html-table-code containing columns within my Query.

EVERYTHING IS WORKING SO FAR:
The PRETAG creates the HTML-Code to generate the correct amount of void cells. e.g. if the 1st of june is a thursday you get <td colspan=3> to get that day in 4forth position. In Europe the week starts with Monday.

CASE WHEN (datepart(month,dia)-datepart(month,dia-1) !=0 AND datepart(weekday, dia)!= 2) THEN '<td colspan=' + CAST(CASE WHEN datepart(weekday, dia) = 1 THEN '6' ELSE datepart(weekday, dia) - 2 END AS VARCHAR) + '></td>' END AS PRETAG

HERE'S THE PROBLEM:
The first date in the DataBase doesn't necessarily have to be the 1st of a month. In this case I have to check in the CASE clause, if a record for the date= day minus one exists in the database. If it doesn't exist, that day has to be proceeded as if it was the first one.

I guess it has to be done with a Self Join, but I can't think of the right syntax in the Case Clause.

Somebody gives me a clue?
Martin

X002548
Not Just a Number

15586 Posts

Posted - 2010-07-02 : 09:51:39
quote:
Originally posted by barnabeck

HERE'S THE PROBLEM:
The first date in the DataBase doesn't necessarily have to be the 1st of a month.



You probably need a numbers table to join to...



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2010-07-02 : 10:51:09
I'm not sure I understand the requirement. But, similar to what Brett suggested, you might be able to make use of a Calender/Date table with a DayOfMonth column..?
Go to Top of Page
   

- Advertisement -