Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problem with a stored procedure

Status
Not open for further replies.

inarobis

IS-IT--Management
Joined
Apr 3, 2006
Messages
71
Location
CH
Hello guys,

I have a problem with a stored procedure in sql server.

I would like to execute this query

declare @sSQL varchar(255)


SET @sSQL =
'SELECT TOP 1 [value], date, name, [times]
FROM (SELECT value, date, times, name
FROM view
WHERE ValueDate =
(SELECT MAX(date) AS maxdate
FROM view v
WHERE (date BETWEEN ''2006-02-01'' AND ''2006-02-28''))) Newtable
WHERE (name = ''TEST'')
GROUP BY [value], date, [times], name
ORDER BY [times] DESC'

EXEC (@sSQL)

When I execute the query I have no problem but ... when i tried to stored it I have this several problem I do not know why ... something like

Line 4: Incorrect syntax near '='

I would like be able to pass variable on it and create function to store the results in a table.

Please someone could help me on that.

Ina
 
varchar(255) is not big enough...

------
[small]select stuff(stuff(replicate('<P> <B> ', 14), 109, 0, '<.'), 112, 0, '/')[/small]
[banghead]
 
and nvarchar is better?
 
Yup.

Run print @sSQL instead of EXEC and you'll see statement is not complete. That's because it is longer than 255 characters... SELECT LEN(yourcode) actually returns 552.

------
[small]select stuff(stuff(replicate('<P> <B> ', 14), 109, 0, '<.'), 112, 0, '/')[/small]
[banghead]
 
Thank you I did it... and it works :D
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top