I've been stuck for the past two days execute it give the error:
The data types varchar and int are incompatible in the concat operator
Here is my 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 the dummy record into dbo.salestable
for working in salestable, debug and step into the code that give the debug and understanding code
declare @outercounter int = 1
declare @innercounter int = 1
while @outercounter <= (select count(name) from namestable)
begin
while @innercounter <= datediff(day, getdate() -datepart(day, getdate()), {fn concat('12/31/',Datepart(year,getdate()))})
begin
insert into 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 * from dbo.salestable
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…