Note that there are some explanatory texts on larger screens.

plurals
  1. POStored Procedure Parameter Causes Error
    primarykey
    data
    text
    <p>I created a stored procedure that takes 3 arguments. I am having an issue with the 2nd argument ([HQ-211-STOCK-DBO]). I've been trying to figure it out for quite some time. </p> <p>Here is the call to the SP:</p> <pre><code>EXEC [dbo].[spColumnsChanged] '[HQ-193-STOCK-DBO]','[HQ-211-STOCK-DBO]','arch_conv_col_diffs' </code></pre> <p>In the SP I have the following code:</p> <pre><code>CREATE PROCEDURE [dbo].[spColumnsChanged] (@sr_database nvarchar(128),@tr_database nvarchar(128),@diff_table nvarchar(128)) </code></pre> <p>...</p> <pre><code>SET @DFCursor = CURSOR FAST_FORWARD FOR SELECT o.name table_name, col.name column_name, t.name data_type, col.max_length, col.is_nullable FROM @tr_database.sys.columns col INNER JOIN @tr_database.dbo.sysobjects o on o.id = col.object_id INNER JOIN @tr_database.sys.types t ON t.user_type_id = col.user_type_id WHERE o.xtype = 'U' -- user tables ORDER BY o.name, col.column_id </code></pre> <p>When I run the SP I receive the error: "(Msg 102, Line 63) Incorrect syntax near '.'."</p> <p>Line 63 is the FROM statement that uses the 3rd argument to the SP. (@tr_database)</p> <p>The interesting thing is if I substitue the actual parameter value for the parameter like this:</p> <pre><code> SELECT o.name table_name, col.name column_name, t.name data_type, col.max_length, col.is_nullable FROM [HQ-211-STOCK-DBO].sys.columns col INNER JOIN [HQ-211-STOCK-DBO].dbo.sysobjects o on o.id = col.object_id INNER JOIN [HQ-211-STOCK-DBO].sys.types t ON t.user_type_id = col.user_type_id WHERE o.xtype = 'U' -- user tables ORDER BY o.name, col.column_id </code></pre> <p>It works fine. </p> <p>Can anyone spot the error?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload