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
 General SQL Server Forums
 New to SQL Server Programming
 Select cast problem

Author  Topic 

masterdineen
Aged Yak Warrior

550 Posts

Posted - 2009-04-28 : 06:00:01
I want to populate a basic orders table or an excerise.

the table is


Create table dbo.orders (
order ID int identity(1.1),
orderDate datetime not null,
orderAmount money not null

Constraint pk_orders Primary Kry Clustered (Orderdate, OrderAmount))
on partscheme(orderID)

The popuate statement is

set nocount on
declare @month int,
@day int

set @month = 1
set @day = 1

while @month <= 12
begin
while @day <= 28
begin
insert dbo.orders (orderDate,orderAmount)
select cast(@month as varchar (2)) + '/' + cast(@day as varchar (2)) + '2005',

@day * 20

set @day = @day + 1
end

set @day = 1
set @month = @month + 1

end
go

and my result is

conversion failed when converting datetime from character string

could someone tell where i am going wrong please

Regards

Rob



MCTS certified

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-04-28 : 06:05:32
select cast(@month as varchar (2)) + '/' + cast(@day as varchar (2)) + '/' + '2005',


E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

masterdineen
Aged Yak Warrior

550 Posts

Posted - 2009-04-28 : 06:08:41
o my god,

you really have to develop a good eye for this dont you.

Im studying for my MCITP at the moment.

thank you for your help

Regards

Rob

MCTS certified
Go to Top of Page
   

- Advertisement -