Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Still working on indirection query
Message
 
À
05/02/2007 08:54:25
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Versions des environnements
SQL Server:
SQL Server 2000
Divers
Thread ID:
01192348
Message ID:
01192363
Vues:
13
>Good idea, using OUT. I am still learning the finer points of T_SQL.
>Unfortunately it gives me an error in SQL Analyzer that it cannot combine vare definition and assignment in same query.
>
>I will try in the Stored Procedure as it sometimes gives different results/errors from SQL Analyzer. I'll work along these lines. Thx.

This works for me, tested agains the data I have.
declare	@domestic 	INT
declare	@TypeId   	INT
set	@domestic=1		-- passed as parameter

DECLARE @Column2Get1	CHAR(20)
DECLARE @Column2Get2	CHAR(20)
DECLARE @Column2Get3	CHAR(20)
DECLARE @Column2Get4	CHAR(20)
SET @Column2Get3=''
SET @Column2Get4=''

DECLARE @sSQL NVARCHAR(500)
DECLARE @retval INT

set @Column2Get1='NAME02'

-- Query #1 to get the names of the columns from SubTypes lookup table
SET @sSQL = N'SELECT DISTINCT @Column2Get3Out=''NAME02'''
SET @sSQL = @sSQL + 'FROM dbo.Config'
--select @sSQL   -- to test
DECLARE @ParamDeff nvarchar(2000)
SET @ParamDeff = '@Column2Get3Out char(20) OUTPUT,  @Column2Get4Out char(20) OUTPUT'


EXECUTE sp_executesql @sSQL, @ParamDeff,  @Column2Get3Out =@Column2Get3 OUTPUT, @Column2Get4Out = @Column2Get4 OUTPUT

-- Query #2 to get the values of the desired columns from Benchmarks lookup table (simplified WHERE clause from original)
-- table (simplified): ItemId (Int), DomC2SBmk (Int), DomC2SMdn (Int), IntlC2SBmk (Int), IntlC2SMdn (Int), ...
SELECT @Column2Get3

SET @sSQL = N'SELECT ' + @Column2Get3
SET @sSQL = @sSQL + 'FROM dbo.Config '
EXEC (@sSql)
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform