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.
| Author |
Topic |
|
Sonu619
Posting Yak Master
202 Posts |
Posted - 2009-12-29 : 20:41:08
|
| I am trying to build query Please help me. Here is the my project:-"Define a variable @FirstDayOfMonth to hold a character string long enough for the date format of your choice. Define a table variable @results that has one column to hold the @FirstDayOfMonth values. For each month of the current year (variable @mo), set @FirstDayOfMonth equal to a constructed character string representing the first day of the month, and insert this @FirstDayOfMonth value into the @results table. After exiting the "month" loop, select all rows from @results. Use of proper data types for your variables is a must." |
|
|
Vinnie881
Master Smack Fu Yak Hacker
1231 Posts |
Posted - 2009-12-29 : 22:03:11
|
Your teacher should work on teaching you using good practices and not this, but here u godeclare @firstdayofmonth char(10), @mo intdeclare @results table(firstdayofmonth datetime)set @mo = 0while @mo < 12beginset @mo = @mo + 1set @firstdayofmonth = convert(char(2),@mo) + '/1/2010'insert into @results(firstdayofmonth)select @firstdayofmonth endselect firstdayofmonth from@results Success is 10% Intelligence, 70% Determination, and 22% Stupidity.\_/ _/ _/\_/ _/\_/ _/ _/- 881 |
 |
|
|
Sonu619
Posting Yak Master
202 Posts |
Posted - 2009-12-30 : 00:14:01
|
| Thanks for your help Vinnie, I tried from all two days after that I request u guys! any way thanks. One more question for you, Any good web sites for T-SQL? Please don't reply use GOOGLE ): |
 |
|
|
senthil_nagore
Master Smack Fu Yak Hacker
1007 Posts |
Posted - 2009-12-30 : 00:17:28
|
quote: Originally posted by Sonu619 Thanks for your help Vinnie, I tried from all two days after that I request u guys! any way thanks. One more question for you, Any good web sites for T-SQL? Please don't reply use GOOGLE ):
Refer thishttp://www.functionx.com/sqlserver/Senthil.C------------------------------------------------------[Microsoft][ODBC SQL Server Driver]Operation canceledhttp://senthilnagore.blogspot.com/ |
 |
|
|
Vinnie881
Master Smack Fu Yak Hacker
1231 Posts |
Posted - 2009-12-30 : 00:53:11
|
Ohh, I wasn't saying it wad a bad practice to ask for help, I was just stating that your teacher is teaching you to use a loop and variables when it's not needed or the propper way to accomplish the task on hand. It's actually a flat out bad practice, and if your teacher wanted to illustrate a loop, there are better alternative so it didn't teach a bad practice. In a real world scenerio, this method will do nothing besides give poor performance over almost ALL other methods. Success is 10% Intelligence, 70% Determination, and 22% Stupidity.\_/ _/ _/\_/ _/\_/ _/ _/- 881 |
 |
|
|
rajdaksha
Aged Yak Warrior
595 Posts |
|
|
Sonu619
Posting Yak Master
202 Posts |
Posted - 2009-12-30 : 01:02:00
|
| This is my first post ever. I really appreciate you guys. You guys are great!Thanks Vinnie for guidance. |
 |
|
|
|
|
|
|
|