Quantcast
Channel: Forum Getting started with SQL Server
Viewing all articles
Browse latest Browse all 7129

Quotes for input parameter

$
0
0

Hy,

I need some help with writing syntax, cause I keep getting warning: Invalid object name '' + @Table + ''

@Table is my input parameter, and I need to use it as such to get an ID from the table I am trying to quote.

ALTER procedure [dbo].[obrPla_DohvatiPrethodniDatum]

@ID int,
@Table nvarchar(50) = null

AS

BEGIN declare

@PreviousID int = null,

@PreviousDate date = null

set @PreviousID = (select MAX(ID) from  "' + @Table + '" where ID < @ID)

if(@PreviousID is not null and @PreviousID > 0)
    begin
        set @PreviousDate = (select DatumOd from "' + @Table + '" where ID = @PreviousID )
    end
else
    begin
        set @PreviousDate = null
    end

select @PrethodniDatum

END

Can any1 explain me what seems to be the problem? Thx.


Viewing all articles
Browse latest Browse all 7129

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>