Print all the months in T-Sql

This is a silly but probably usefull function in T-SQL, print all the months:

set language spanish
declare @counter int
set @counter = 0
while @counter

begin
set @counter = @counter + 1
print DateName( month , DateAdd( month , @counter , 0 ) - 1 )
end
Advertisements

One thought on “Print all the months in T-Sql

  1. Crea la siguiente función:SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGOCREATE FUNCTION ftObtenerMeses ( — Add the parameters for the function here)RETURNS @Meses TABLE ( — Add the column definitions for the TABLE variable here [NumeroMes] int, [NombreMes] varchar(10))ASBEGIN — Fill the table variable with the rows for your result set DECLARE @counter int =0 WHILE @counter <12 BEGIN SET @counter = @counter + 1 INSERT INTO @Meses ( [NumeroMes],[NombreMes]) VALUES ( @counter, DateName( month , DateAdd( month , @counter , 0 ) – 1 ) ) –SET @MinValue = @MinValue + 1 END RETURN ENDGODespués para invocar la función has lo siguiente:SET language spanish–us_englishSELECT *FROM ftObtenerMeses()

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s