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.

 All Forums
 Old Forums
 CLOSED - General SQL Server
 Stored procedure runs with no effect to the database with no errors

Author  Topic 

Ask SQLTeam Question

0 Posts

Posted - 2003-01-15 : 14:53:44
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



12543 Posts

Posted - 2003-01-15 : 16:58:45
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

- Advertisement -