Quantcast
Channel: SQL Server Integration Services forum
Viewing all articles
Browse latest Browse all 24688

How does SQL Command From Variable works?

$
0
0

I have script which runs in management studio and gives me the MaxPeriod, Here's the script

declare @maxPeriod varchar(6)
select @MaxPeriod=period from openquery(pmaxlink,'select max(period) period 
from max.v_max_xs_product_usage where period_type = ''M''')
select CAST(CAST(SUBSTRING(@maxPeriod,1,4) AS INT) - 2  AS VARCHAR(4)) 
+ CASE WHEN CAST(SUBSTRING(@maxPeriod,5,2) AS INT) + 1 < 10 THEN '0' 
ELSE '' END + CAST(CAST(SUBSTRING(@maxPeriod,5,2) AS INT) + 1  AS VARCHAR(4))

I want to put the result from this script into a variable say MaxPeriod and use the variable value in script "Select * from max.v_maxtable where periodtype = 'M' and period > = " + @[user::MaxPeriod]

I created two variables in SSIS MaxPeriod and Result and both having String datatype.

I will put this select statement in variable Result and use this variable in OLEDB source. I guess i am going right but the question is when i put the Delcare..script in execute sql task having full result set to variable MaxPeriod and execute i get error : "The type of the value being assigned to variable "User::MaxPeriod" differs from the current variable type.


Viewing all articles
Browse latest Browse all 24688

Trending Articles



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