Please start any new threads on our new site at http://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Error in Execute command
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

shinoykurian
Starting Member

United Arab Emirates
4 Posts

Posted - 04/22/2009 :  03:04:10  Show Profile  Send shinoykurian an AOL message  Click to see shinoykurian's MSN Messenger address  Send shinoykurian a Yahoo! Message  Reply with Quote
Hi guys, I am getting an error message for the below query, can some one help.

DECLARE tables_cursor CURSOR
FOR
SELECT RESCOD,ITMCOD FROM psmastbl WHERE rescod='GSH'
OPEN tables_cursor
DECLARE @restaurant varchar(3)
DECLARE @tablename decimal
FETCH NEXT FROM tables_cursor INTO @restaurant,@tablename
WHILE (@@FETCH_STATUS <> -1)
BEGIN
EXEC ('SELECT * FROM PSMASTBL WHERE RESCOD='+@restaurant)
print @tablename;
print @restaurant;
FETCH NEXT FROM tables_cursor INTO @restaurant,@tablename
END
CLOSE tables_cursor
DEALLOCATE tables_cursor

error
Msg 207, Level 16, State 1, Line 1
Invalid column name 'GSH'.
1
GSH
Msg 207, Level 16, State 1, Line 1
Invalid column name 'GSH'.
2

CREATE TABLE [dbo].[PSMASTBL](
[APPDAT] [decimal](8, 0) NOT NULL,
[RESCOD] [varchar](3) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[ITMCOD] [decimal](4, 0) NOT NULL,
[ITMNAM] [varchar](40) COLLATE SQL_Latin1_General_CP1_CI_AS NULL DEFAULT (' '),
[SHTNAM] [varchar](10) COLLATE SQL_Latin1_General_CP1_CI_AS NULL DEFAULT (' '),
PRIMARY KEY CLUSTERED
(
[APPDAT] ASC,
[RESCOD] ASC,
[ITMCOD] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]

INSERT INTO PSMASTBL( APPDAT, RESCOD, ITMCOD, ITMNAM, SHTNAM) VALUES ( 20090101, 'GSH', 1, 'TEST1', '222')
INSERT INTO PSMASTBL( APPDAT, RESCOD, ITMCOD, ITMNAM, SHTNAM) VALUES ( 20090101, 'GSH', 2, 'TEST2', '333')
INSERT INTO PSMASTBL( APPDAT, RESCOD, ITMCOD, ITMNAM, SHTNAM) VALUES ( 20090101, 'GSH', 3, 'TEST3', '444')

Thanks!
Shinoy

Edited by - shinoykurian on 04/22/2009 03:27:45

sanoj_av
Posting Yak Master

India
118 Posts

Posted - 04/22/2009 :  03:37:44  Show Profile  Reply with Quote
DECLARE tables_cursor CURSOR
FOR
SELECT RESCOD,ITMCOD FROM psmastbl WHERE rescod='GSH'
OPEN tables_cursor
DECLARE @restaurant varchar(3)
DECLARE @tablename decimal
FETCH NEXT FROM tables_cursor INTO @restaurant,@tablename
WHILE (@@FETCH_STATUS <> -1)
BEGIN

EXEC ('SELECT * FROM PSMASTBL WHERE RESCOD='''+@restaurant+'''')

FETCH NEXT FROM tables_cursor INTO @restaurant,@tablename
END
CLOSE tables_cursor
DEALLOCATE tables_cursor

Edited by - sanoj_av on 04/22/2009 03:39:11
Go to Top of Page

shinoykurian
Starting Member

United Arab Emirates
4 Posts

Posted - 04/22/2009 :  03:47:37  Show Profile  Send shinoykurian an AOL message  Click to see shinoykurian's MSN Messenger address  Send shinoykurian a Yahoo! Message  Reply with Quote
Thanks very much.

Best Regards
Shinoy
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000