我需要从数据库CreditAdvisor_PrimaryCode
返回一个字段DWH_Staging
,其中来自数据库CooperationEndDate
的字段DWH_Staging
不会覆盖来自某个字段DatumUkonceni
的字段adm.MaxBatch
变量名称的数据库。我们有一个过程DECLARE @db_is NVARCHAR(50)
DECLARE @string NVARCHAR(MAX)
SET @db_is = (
SELECT mb.DatabaseName
FROM adm.MaxBatch mb
WHERE mb.SourceID = 1
)
SET @string = 'SELECT
ca.CreditAdvisorCode_Primary
FROM ' + @db_is + '..CS_Prodejci prod
JOIN ' + @db_is + '..CS_OZ oz ON prod.RC = oz.OZ_RC
JOIN DWH_Staging.dim.CreditAdvisor ca ON oz.KodOZ = ca.CreditAdvisorCode_Primary
WHERE prod.KonecCinnosti <> ca.CooperationEndDateId'
PRINT @string
EXEC (@string)
返回带有变量名的数据库的实际名称。 SP如下:
//button[@value='Save Changes']
//button[@value='Save Changes' and @type='submit']
仅返回文本输出。 任何帮助都会受到重视。感谢。
答案 0 :(得分:0)
如果您尝试:
DECLARE @db_is NVARCHAR(50)
DECLARE @string NVARCHAR(MAX)
SET @db_is = N'S01_20170904'
/*= (
SELECT mb.DatabaseName
FROM adm.MaxBatch mb
WHERE mb.SourceID = 1
)
*/
SET @string = N'SELECT
ca.CreditAdvisorCode_Primary
FROM [' + @db_is + ']..[CS_Prodejci] prod
JOIN [' + @db_is + ']..[CS_OZ] oz ON prod.RC = oz.OZ_RC
JOIN DWH_Staging.dim.CreditAdvisor ca ON oz.KodOZ = ca.CreditAdvisorCode_Primary
WHERE prod.KonecCinnosti <> ca.CooperationEndDateId'
EXEC sp_executesql @string
它对你有用吗?