sql - The data types varchar and int are incompatible in the concat operator -
i've been stuck past 2 days execute give error:
the data types varchar , int incompatible in concat operator
here table:
create table salestable ( id int identity(1,1) not null primary key, empid char(5), datesold date, monthonly varchar(50), amount money )
this code inserts dummy record dbo.salestable
working in salestable, debug , step code give debug , understanding code
declare @outercounter int = 1 declare @innercounter int = 1 while @outercounter <= (select count(name) namestable) begin while @innercounter <= datediff(day, getdate() -datepart(day, getdate()), {fn concat('12/31/',datepart(year,getdate()))}) begin insert salestable (empid, datesold, monthonly, amount) values (@outercounter, getdate() - datepart(day, getdate()) + @innercounter, datename(month, getdate() - datepart(day, getdate()) + @innercounter), rand() * 10000) set @innercounter = @innercounter +1 end set @outercounter = @outercounter + 1 set @innercounter = 1 end select * dbo.salestable
fn concat('12/31/',cast(datepart(year,getdate()) varchar(10)))
try this
Comments
Post a Comment