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 dencom on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL SERVER 2000 Dynamic sql is not working 1

Status
Not open for further replies.

tempo1

Programmer
Feb 20, 2007
118
Hi everyone
The code i wrote is:
Code:
DECLARE @dynamic VARCHAR(1000)
SET @dynamic=
'
SELECT 
accountno "accountno"
FROM
fiftyplus..contact1
'
print @dynamic
exec @dynamic
not working ! I get an error message saying:
SELECT
accountno "accountno"
FROM
fiftyplus..contact1
Server: Msg 203, Level 16, State 2, Line 10
The name '
SELECT
accountno "accountno"
FROM
fiftyplus..contact1
' is not a valid identifier.
And i cant figure out why ! Can anyone tell me whats wrong
with it ?
Thanks
 
try this...
Code:
DECLARE @dynamic VARCHAR(1000)
SET @dynamic=
'
SELECT
accountno as accountno
FROM
fiftyplus..contact1
'
print @dynamic
exec @dynamic

- Paul
- If at first you don't succeed, find out if the loser gets anything.
 
This will give the same too.

Code:
DECLARE @dynamic VARCHAR(1000)
SET @dynamic=
'SELECT accountno 
FROM fiftyplus..contact1'

print @dynamic
exec @dynamic

- Paul
- If at first you don't succeed, find out if the loser gets anything.
 
Hi ptheriault,
And thanks.
I get the following error message
Could not find stored procedure '
SELECT
accountno,
lastname,
secr,
mergecodes

FROM
contact1
'.
Thanks
 
Change:
exec @dynamic

To:
exec [!]([/!]@dynamic[!])[/!]

-George

"the screen with the little boxes in the window." - Moron
 
Hi gmmastros,
Thanks a lot.
Thats trivial..
I was dealing with something much more complicated and maybe this is what made me forgetting the brackets..[blush] Hopefully this is the reason to all my troubles..
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top