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.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Need Help

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 go

declare @firstdayofmonth char(10), @mo int
declare @results table(firstdayofmonth datetime)
set @mo = 0

while @mo < 12
begin
set @mo = @mo + 1
set @firstdayofmonth = convert(char(2),@mo) + '/1/2010'
insert into @results(firstdayofmonth)
select @firstdayofmonth
end
select firstdayofmonth
from
@results



Success is 10% Intelligence, 70% Determination, and 22% Stupidity.
\_/ _/ _/\_/ _/\_/ _/ _/- 881
Go to Top of Page

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 ):
Go to Top of Page

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 this

http://www.functionx.com/sqlserver/

Senthil.C
------------------------------------------------------
[Microsoft][ODBC SQL Server Driver]Operation canceled

http://senthilnagore.blogspot.com/
Go to Top of Page

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
Go to Top of Page

rajdaksha
Aged Yak Warrior

595 Posts

Posted - 2009-12-30 : 00:54:27
Hi


http://technet.microsoft.com/en-us/library/ms365303.aspx
http://www.w3schools.com/SQl/default.asp

http://www.sqlservertutorials.com/introduction_to_t-sql.html
http://www.sql-tutorial.net/

-------------------------
R...
Go to Top of Page

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.
Go to Top of Page
   

- Advertisement -