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

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Creating Table on different Server using Variables
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Macro1
Starting Member

8 Posts

Posted - 10/15/2010 :  05:25:51  Show Profile  Reply with Quote
Hi,

I was just wondering if anybody could help me out with the correct syntax to run a stored procedure from one server to create a table on a different server. The problem I'm having is that the server, database name and table name are going to vary everytime so I'm passing variables through.

DECLARE @TableName AS varchar(100)
SET @TableName = Map_'+LTRIM(RTRIM(REPLACE(REPLACE(REPLACE(REPLACE(@PortNum, ' ',''),'+',''),',',''),'&','')))

CREATE TABLE @ServerName.@DBName.@TableName
	(
	ID VARCHAR(10) NULL,
	COUNTRY VARCHAR(2) NULL,
	CRESTA VARCHAR(5) NULL,
	TSIUSD FLOAT NULL,
	TSI FLOAT NULL,
	MrkTSI FLOAT NULL,
	Mshare FLOAT NULL
	)


Is this syntax correct?

Thanks in advance

Edited by - Macro1 on 10/15/2010 05:26:26

webfred
Flowing Fount of Yak Knowledge

Germany
8683 Posts

Posted - 10/15/2010 :  05:42:55  Show Profile  Visit webfred's Homepage  Reply with Quote
Is this syntax correct?

No it isn't.

You need dynamic sql for that.
If you don't know about dynamic sql then you have to learn.
http://www.sommarskog.se/dynamic_sql.html

In the first step you should work against the goal to create a table on the same server.

In the next step you can work against the goal to create a table on another server.
For this it is needed to have a linked server (you know I already told you that in your old thread)
If you don't know about linked server then you have to learn.
http://www.databasejournal.com/features/mssql/article.php/3085211/Linked-Servers-on-MS-SQL-Part-1.htm



No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New 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