Hi,
I am newbie to SQL, please be gentle with me (DISCLAIMER).
Anyway, I have a few questions and would like to throw them out one at a time.
Frist question, I get the error "The number of variables declared in the INTO list must match that of selected columns." Help please?!
This is what I have:
declare @mytoday as char(10)
declare @c_myday as char(2)
declare @c_mymonth as char(2)
declare @c_myyear as char(4)
declare @mytable as char(16)
declare @c_rowdate as char(10)
declare @myhour as char(2)
declare @myrowdate as int
declare @ihour as int
declare @myCounter as int
declare @i_myday as int
declare @i_mymonth as int
declare @i_myyear as int
set @myCounter = 0
set @i_myday = datepart(dd, getdate())
set @i_mymonth = datepart(mm, getdate())
set @i_myyear = datepart(yyyy, getdate())
set @c_myday = cast(@i_myday AS char(2))
set @c_mymonth = cast(@i_mymonth AS char(2))
set @c_myyear = cast(@i_myyear AS char(4))
IF LEN(@c_myday) = 1
set @c_myday = '0' + @c_myday
IF LEN(@c_mymonth) = 1
set @c_mymonth = '0' + @c_mymonth
set @mytoday = @c_myyear + @c_mymonth + @c_myday
declare cch CURSOR FOR
select sourceid, rowdate, count(*)
from cmscallhistory
where left(rowdate, 8) = @mytoday
group by sourceid, rowdate
order by sourceid, rowdate
OPEN cch
FETCH NEXT FROM cch
INTO @myrowdate
while @@FETCH_STATUS = 0
BEGIN
set @myCounter = @myCounter + 1
set @c_rowdate = cast(@myrowdate AS char(10))
set @myhour = cast(right(@c_rowdate, 2) as int)
set @ihour = cast(@myhour AS int) + 1
set @myhour = cast(@ihour AS char(2))
IF LEN(@myhour) = 1
set @myhour = '0' + @myhour
set @c_rowdate = right(@c_rowdate, 8) + @myhour
set @myrowdate = cast(@c_rowdate AS int)
FETCH NEXT FROM cch -- get next value
INTO @myrowdate
END
CLOSE cch --- close CURSOR
DEALLOCATE cch --- memory cleanup
I am newbie to SQL, please be gentle with me (DISCLAIMER).
Frist question, I get the error "The number of variables declared in the INTO list must match that of selected columns." Help please?!
This is what I have:
declare @mytoday as char(10)
declare @c_myday as char(2)
declare @c_mymonth as char(2)
declare @c_myyear as char(4)
declare @mytable as char(16)
declare @c_rowdate as char(10)
declare @myhour as char(2)
declare @myrowdate as int
declare @ihour as int
declare @myCounter as int
declare @i_myday as int
declare @i_mymonth as int
declare @i_myyear as int
set @myCounter = 0
set @i_myday = datepart(dd, getdate())
set @i_mymonth = datepart(mm, getdate())
set @i_myyear = datepart(yyyy, getdate())
set @c_myday = cast(@i_myday AS char(2))
set @c_mymonth = cast(@i_mymonth AS char(2))
set @c_myyear = cast(@i_myyear AS char(4))
IF LEN(@c_myday) = 1
set @c_myday = '0' + @c_myday
IF LEN(@c_mymonth) = 1
set @c_mymonth = '0' + @c_mymonth
set @mytoday = @c_myyear + @c_mymonth + @c_myday
declare cch CURSOR FOR
select sourceid, rowdate, count(*)
from cmscallhistory
where left(rowdate, 8) = @mytoday
group by sourceid, rowdate
order by sourceid, rowdate
OPEN cch
FETCH NEXT FROM cch
INTO @myrowdate
while @@FETCH_STATUS = 0
BEGIN
set @myCounter = @myCounter + 1
set @c_rowdate = cast(@myrowdate AS char(10))
set @myhour = cast(right(@c_rowdate, 2) as int)
set @ihour = cast(@myhour AS int) + 1
set @myhour = cast(@ihour AS char(2))
IF LEN(@myhour) = 1
set @myhour = '0' + @myhour
set @c_rowdate = right(@c_rowdate, 8) + @myhour
set @myrowdate = cast(@c_rowdate AS int)
FETCH NEXT FROM cch -- get next value
INTO @myrowdate
END
CLOSE cch --- close CURSOR
DEALLOCATE cch --- memory cleanup