Please start any new threads on our new site at 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
Save Password
Forgot your Password?

 All Forums
 Old Forums
 CLOSED - General SQL Server
 Stored procedure runs with no effect to the database with no errors
 Forum Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

Ask SQLTeam Question

0 Posts

Posted - 01/15/2003 :  14:53:44  Show Profile  Visit AskSQLTeam's Homepage
Pranali writes "I am trying to Insert into a table by selecting records by a Select query from a different database

CREATE PROCEDURE InsertTemp3M @dbName varchar(30),@TabName varchar(30), @strSQL varchar(1000) out(checking the query)

Declare @SQL VarChar(2000)

SELECT @SQL='INSERT INTO ' + @TabName + '(' + ' batchNumber' + ')'
SELECT @SQL = @SQL + ' SELECT convert(int,ascii(' + "'batchNumber'" + ')) FROM ' + @dbName +'.dbo.indexFile'
select @sql = ascii(@sql)
return @SQL
EXEC sp_executesql @SQL

The parameters are passed thru VB .
This sp runs fine without any error both in sp and query analyser ,but no records are added to the database
dbname is used for selecting records from diff database and added to tables in current database.

1.if I remove the ascii conversion above gives me error
245 Syntax error converting the %ls value '%.*ls' to a column of data type %ls.

2.same error if I dont use convert ..

3.this is a truncated query its very lomg but I cut it short for testing.

4.The batchnumber field is int in both tables source and destination.

Please HELP



United Kingdom
12543 Posts

Posted - 01/15/2003 :  16:58:45  Show Profile  Visit nr's Homepage
return @SQL
This will return from the SP without doing the exec.

Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
  Previous Topic Topic Next Topic  
 Forum Locked
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.02 seconds. Powered By: Snitz Forums 2000