Create Function dbo.GetWeekdayNames
(
@Value Integer
)
Returns VarChar(100)
As
Begin
Declare @Sunday Integer
Declare @Monday Integer
Declare @Tuesday Integer
Declare @Wednesday Integer
Declare @Thursday Integer
Declare @Friday Integer
Declare @Saturday Integer
Set @Sunday = 1
Set @Monday = 2
Set @Tuesday = 4
Set @Wednesday = 8
Set @Thursday = 16
Set @Friday = 32
Set @Saturday = 64
Declare @Result VarChar(100)
Set @Result = ''
If @Value & @Sunday <> 0
Set @Result = @Result + 'Sunday,'
If @Value & @Monday <> 0
Set @Result = @Result + 'Monday,'
If @Value & @Tuesday <> 0
Set @Result = @Result + 'Tuesday,'
If @Value & @Wednesday <> 0
Set @Result = @Result + 'Wednesday,'
If @Value & @Thursday <> 0
Set @Result = @Result + 'Thursday,'
If @Value & @Friday <> 0
Set @Result = @Result + 'Friday,'
If @Value & @Saturday <> 0
Set @Result = @Result + 'Saturday,'
If Right(@Result, 1) = ','
Set @Result = Left(@Result, Len(@Result)-1)
Return @Result
End