| Author |
Topic |
|
ischenk
Starting Member
15 Posts |
Posted - 2008-07-15 : 17:58:48
|
| Can anyone tell me why this syntax won't work?declare @FirstDayOfMonth varchar(10)declare @charmo intdeclare @mo intset @mo = 1while @mo <= 12beginif @mo <= 9 set @charmo = '0' + cast(@mo as char(1))else set @charmo = cast(@mo as char(2))set @FirstDayOfMonth = @charmo + '-01' + cast(year(getdate()) as char(4))declare @results tableinsert @results values (@FirstDayOfMonth)set @mo = @mo + 1end |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2008-07-15 : 18:03:53
|
| You haven't specified the table layout for @results.DECLARE @results table (...) -- perhaps FirstDayOfMonth varchar(10)?Tara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/Subscribe to my blog |
 |
|
|
ischenk
Starting Member
15 Posts |
Posted - 2008-07-15 : 18:07:07
|
| I'm not sure how to do a table layout. This is the error I am recieving:Msg 156, Level 15, State 1, Line 14Incorrect syntax near the keyword 'insert'. |
 |
|
|
ischenk
Starting Member
15 Posts |
Posted - 2008-07-15 : 18:10:15
|
| Putting @FirstDayOfMonth varchar(10) didn't do any good.Anything else I should try? |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2008-07-15 : 18:11:10
|
| I showed it in my last post. Just replace ... with what you want to name the column and your data type. I even showed an example after the --.declare @results table (firstdayofmonth varchar(10))Tara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/Subscribe to my blog |
 |
|
|
ischenk
Starting Member
15 Posts |
Posted - 2008-07-15 : 18:13:25
|
| Then it gives me this error:Msg 102, Level 15, State 1, Line 13Incorrect syntax near '@FirstDayOfMonth'. |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
ischenk
Starting Member
15 Posts |
Posted - 2008-07-15 : 18:27:44
|
| Okay, I was putting the @ symbol into the layout. That is why it would not work. Now, though, can you show me how to print this information? here is the final code:declare @FirstDayOfMonth varchar(10)declare @charmo intdeclare @mo intset @mo = 1while @mo <= 12beginif @mo <= 9 set @charmo = '0' + cast(@mo as char(1))else set @charmo = cast(@mo as char(2))set @FirstDayOfMonth = @charmo + '-01' + cast(year(getdate()) as char(4))declare @results table (FirstDayOfMonth varchar(10))insert @results values (@FirstDayOfMonth)set @mo = @mo + 1end |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
ischenk
Starting Member
15 Posts |
Posted - 2008-07-15 : 18:39:47
|
| Thank you so much. It worked perfectly. I am still in the stages where scripting confuses me. This was a huge help. |
 |
|
|
|