Reputation: 1
How i can compare variables @PersoanaAnterioara
and @PersoanaCurenta
?
Incorrect syntax near '@PersoanaCurenta'.--error
drop table #MyTmpData
DECLARE
@PersoanaCurenta nvarchar(100),
@PersoanaAnterioara nvarchar(100),
@Cunostinte nvarchar(50),
@CunostinteTotale nvarchar(max) ,
@ok int
select row_number() over (order by persoana) as RowID, a.*
into #MyTmpData
from ex..tpersoane a
Declare @Step int
Declare @count int
set @count=(select count(RowId) from #MyTmpData)
set @Step = 0
set @ok=0
set @PersoanaCurenta=null
set @PersoanaAnterioara=null
while (@count > @Step)
BEGIN
SET @Step = @Step + 1
select @PersoanaCurenta=persoana , @Cunostinte = cunostinte
from #MyTmpData
where @Step=RowID
if @PersoanaAnterioara is not null and @PersoanaAnterioara != @PersoanaCurenta
end
Incorrect syntax near '@PersoanaCurenta'.
Upvotes: 0
Views: 119
Reputation: 644
Below query is running fine :
DECLARE
@PersoanaCurenta nvarchar(100),
@PersoanaAnterioara nvarchar(100),
@Cunostinte nvarchar(50),
@CunostinteTotale nvarchar(max) ,
@ok int
set @PersoanaCurenta=null
set @PersoanaAnterioara=null
if @PersoanaAnterioara is null and @PersoanaAnterioara != @PersoanaCurenta
SELECT 1
ELSE
SELECT 2
So please recheck you question. Just try this it will work :
drop table #MyTmpData
DECLARE
@PersoanaCurenta nvarchar(100),
@PersoanaAnterioara nvarchar(100),
@Cunostinte nvarchar(50),
@CunostinteTotale nvarchar(max) ,
@ok int
select row_number() over (order by persoana) as RowID, a.*
into #MyTmpData
from ex..tpersoane a
Declare @Step int
Declare @count int
set @count=(select count(RowId) from #MyTmpData)
set @Step = 0
set @ok=0
set @PersoanaCurenta=null
set @PersoanaAnterioara=null
while (@count > @Step)
BEGIN
SET @Step = @Step + 1
select @PersoanaCurenta=persoana , @Cunostinte = cunostinte
from #MyTmpData
where @Step=RowID
if @PersoanaAnterioara is not null and @PersoanaAnterioara != @PersoanaCurenta
SELECT 1
ELSE
SELECT 2
end
Upvotes: 0
Reputation: 1870
There is BEGIN END block is missing in your query at last line.
You started If condition but nothing write in it.
That’s why its giving you error
‘Incorrect syntax near '@PersoanaCurenta'.
Upvotes: 1