Rajiv
Rajiv

Reputation: 685

day flag in sql

I have a web form through which enables the what events can be booked. One of the parameter is that the event can be booked during any days of the week: Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday

The web form contains check boxes for choosing the days. Based on the selection I would like to store the information in a sql table. I am planning to create a secondary master table for the event that will store the information for each day of the week in separate column. With this approach I may ending up wasting spaces.

Below is the table structure of the Primary Master table:

PoojaID      int
DeityID      int
WorshipID    int
PoojaName    char
TimeOfPooja  char
Rate         money

Please advice on the best approach on how I can store? One way, I thought was to store the info in a single column like Su,Mo,Tu,We,Th,Fr,Sa

Upvotes: 0

Views: 123

Answers (2)

Will In The World
Will In The World

Reputation: 276

You can store the values in a single column using a binary representation and store it as a tinyint. Then just store the decimal value.

Sunday | Monday | Tuesday | Wednesday | Thursday | Friday | Saturday | Blank | Binary   | Decimal
0      | 0      | 0       | 0         | 0        | 0      | 1        | 0     | 01000000 | 64

Sunday | Monday | Tuesday | Wednesday | Thursday | Friday | Saturday | Blank | Binary   | Decimal
1      | 1      | 1       | 1         | 1        | 1      | 1        | 0     | 01111111 | 127

`

Upvotes: 0

Munavvar Husein Shaikh
Munavvar Husein Shaikh

Reputation: 583

Just add one column i.e. event date, and just add another column event day, this column is expression column contains an expression

DATENAME(dw, EventDate)

Upvotes: 1

Related Questions