May 17, 2006 at 1:22 pm
I am trying to do an sp that send the top n transaction that the user want, but I don't know how to do it, this isn't works:
declare @n as int
set @n=3
SELECT TOP @n notrans, NOTARJETA, NOCLIENTE
FROM TBMOVIMIENTOS
WHERE NOCLIENTE=10 AND NOEMPLE='0000000124'
ORDER BY nocliente, noemple, NOTRANS desc
May 17, 2006 at 1:26 pm
Place parentheses around @n:
SELECT TOP (@n) notrans, NOTARJETA, NOCLIENTE
-Eddie
Eddie Wuerch
MCM: SQL
May 17, 2006 at 1:36 pm
I do the next change, and I get and error:
Server: Msg 170, Level 15, State 1, Line 5
Line 5: Incorrect syntax near '('.
What I am doing wrong?
declare @n as int
set @n=3
select @n
SELECT TOP (@n) notrans, NOTARJETA, NOCLIENTE
FROM TBMOVIMIENTOS
WHERE NOCLIENTE=10 AND NOEMPLE='0000000124'
ORDER BY nocliente, noemple, NOTRANS desc
May 17, 2006 at 2:42 pm
that works for 2005
you must be using 2000
May 17, 2006 at 2:46 pm
declare @n as int
declare @sql_cmd as varchar(4000)
set @n=3
set @sql_cmd='SELECT TOP '+cast(@n as varchar(10))+' notrans, NOTARJETA, NOCLIENTE
FROM TBMOVIMIENTOS
WHERE NOCLIENTE=10 AND NOEMPLE='+char(39)+'0000000124'+char(39)+'
ORDER BY nocliente, noemple, NOTRANS desc'
exec (@sql_cmd)
should work for 2000
May 17, 2006 at 3:32 pm
Yes I am using 2000, thank you for you help.
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply