Anyone got any Ideas on how to set tax...TXZip as a variable in the following script segment?
Select
RecordID = Identity(int,1,1),
Zip_ZipCode,
Zip_SignatureCode
Into #Temp
from tempstatezip
where State = @State
Delete From tax...TXZIP ------------------------------
While (Select Count(*) from #temp)>0
Begin
Set @rowVal = (Select top 1 RecordID from #Temp)
Id like to set this up in a store procedure so I can pass the state variable to it.....
Having problems setting a linked server as a variable thou.....
Example of what I want.....
Delete from @StateVar
But as a linked server I always get...
declare @StateVar Varchar(11)
Set @StateVar = 'Tax...TXZip'
Select * from @StateVar
Msg 137, Level 15, State 2, Line 3
Must declare the variable '@StateVar'.
I'm posting this because I found this solution after much digging.
The goal here is to incorporate a variable parameter within a OPENQUERY and, ultimately build a dynamic Where clause for use within a OPENQUERY linked server routine. I'm posting because I spent a lot of time trying to get this to work and also, have seen other posts here that hinted it wasn't doable.
First of all - there a good quick article that gets close for FoxPro and possibly works as is for ACCESS:
SET @FAMILY='Touring' SET @OPENQUERY = 'SELECT * FROM OPENQUERY(VFP,'''
SET @TSQL = 'select cov,family,model from vinmast where family='+'['+@FAMILY+']'')'
EXEC (@OPENQUERY+@TSQL)
All shown are single quotes.
In Visual Foxpro, ' ' or " " or [ ] can be used a delimeters
In addition, if wanting to build a dynamic where clause, you could do something like:
SET @TSQL = 'select cov,family,model from vinmast ' IF <some condition met to include FAMILY filter> Begin SET @TSQL=@TSQL+'where family=['+@DUTFAMILY+']''' SET @TSQL=@TSQL+ ')' End ----------------- Here's the entire Stored Procedure:
CREATE PROCEDURE dbo.ewo_sp_DUTLookup ( @DUTPROJECT char(25)=NULL,--Project @DUTFAMILY char(10)=NULL,--Family @DUTMODEL char(20)=NULL,--Model @DUTYEAR char(4)=NULL,--Model Year @DUTBEGIN char(25)=NULL,--Beginning of COV/DUT number @DEBUG int=0 )
AS
DECLARE @OPENQUERY varchar(4000), @TSQL varchar(4000), @TWHERE varchar(4000), @intErrorCode int
IF @intErrorCode=0 Begin SET @OPENQUERY = 'SELECT * FROM OPENQUERY(VFP,''' SET @TSQL = ' select dut_pk,cov,family,model,project,modelyr from vinmast ' End
set @intErrorCode = @@ERROR
IF @intErrorCode = 0 and @DUTFAMILY is not NULL or @DUTMODEL is not NULL or @DUTPROJECT is not NULL or @DUTYEAR is not NULL or @DUTBEGIN is not NULL set @TWHERE=' where '
-- Check for Family criteria If @intErrorCode = 0 and @DUTFAMILY is not NULL and Len(@TWHERE)>0 SET @TWHERE=@TWHERE+' family=['+@DUTFAMILY+'] AND ' set @intErrorCode = @@ERROR
-- Check for Model criteria If @intErrorCode = 0 and @DUTMODEL is not NULL and Len(@TWHERE)>0 SET @TWHERE=@TWHERE+' model=['+@DUTMODEL+'] AND ' set @intErrorCode = @@ERROR
--Check for Project criteria If @intErrorCode = 0 and @DUTPROJECT is not NULL and Len(@TWHERE)>0 SET @TWHERE=@TWHERE+' project=['+@DUTPROJECT+'] AND ' set @intErrorCode = @@ERROR
--Check for Model Year If @intErrorCode = 0 and @DUTYEAR is not NULL and Len(@TWHERE)>0 SET @TWHERE=@TWHERE+' modelyr=['+@DUTYEAR+'] AND ' set @intErrorCode = @@ERROR
--Check for beginning of DUT If @intErrorCode = 0 and @DUTBEGIN is not NULL and Len(@TWHERE)>0 Begin SET @DUTBEGIN=RTRIM(@DUTBEGIN) SET @TWHERE=@TWHERE+' substr(cov,1,'+cast(len(@DUTBEGIN) as char(20))+')=['+@DUTBEGIN+'] AND ' End set @intErrorCode = @@ERROR
IF @intErrorCode=0 AND substring(@TWHERE,Len(@TWHERE)-3,4)=' AND ' Begin set @TWHERE=Substring(@TWHERE,1,Len(@TWHERE)-3) select @intErrorCode=@@ERROR End
SET @TWHERE=@TWHERE+''')'
IF @debug<>0 and @intErrorCode=0 Begin print @intErrorCode print @OPENQUERY print @TSQL print @TWHERE print @OPENQUERY+@TSQL+@TWHERE End
IF @intErrorCode=0 EXEC (@OPENQUERY+@TSQL+@TWHERE) GO
I have created a variable in a SQL Task and assigned it to a string variable. When I debug the container with a breakpoint, I can see the correct date value being assigned to the variable.
I have an ADO Net source setup to an Oracle connection. I need to pull the Oracle data down that has an updated date greater than the updated date in my ODS.
My issue is that the variable is not being passed through to my expression that I use for an ADO Net source.
"SELECT * FROM BI_EDW.GL_JE_HEADERS WHERE LAST_UPDATE_DATE > To_Date('" + (DT_WSTR, 19) @[User::varLastUpdateDate] + "','yyyy-mm-dd hh24:mi:ss')"
I have a SQL Task that updates running totals on a record inserted using a Data Flow Task. The package runs without error, but the actual row does not calculate the running totals. I suspect that the inserted record is not committed until the package completes and the SQL Task is seeing the previous record as the current. Here is the code in the SQL Task:
DECLARE @DV INT; SET @DV = (SELECT MAX(DateValue) FROM tblTG); DECLARE @PV INT; SET @PV = @DV - 1;
I've not been successful in passing a SSIS global variable to a declared parameter, but is it possible to do this:
DECLARE @DV INT; SET @DV = ?; DECLARE @PV INT; SET @PV = @DV - 1;
I have almost 50 references to these parameters in the query so a substitution would be helpful.
I am building a generic SSIS where it takes a text source file and converts to a destination source file . However in the process I want to set the row delimiter and the column delimiter dynamically through the package variable. So that I can use it for any file transfer.
I saw the option for row delimiter in the file connection string property but did not see any column delimiter option.
Is it possible to assign multiple columns from a SQL query to one variable. In the below query I have different variable (email, fname, month_last_taken) from same query being assigned to different columns, can i pass all columns to one variable only and then extract that column out of that variable later? This way I just need to write the query once in the complete block.
DECLARE @email varchar(500) ,@intFlag INT ,@INTFLAGMAX int ,@TABLE_NAME VARCHAR(100)
I hope someone can help me on this one, as I am getting a bit frustrated with my research..
I have procA on ServerA.DatabaseA and it uses an input parameter to get a value that determines which server to ping.
If this parameter is @paramA = 1, then query into LinkedSrvX. If @paramB = 2, then query into LinkedSrvY... etc.
Is there an easier way to do this or a best practice? I really don't want to go into repeating my queries for every server. Here is a tsql mini version of what I am trying to enhance as my original queries are 1000 lines long and I need to get away from the repeated queries. I do have queries that ping within the server and to other linked servers as well without issues.
All linked servers referenced below have the same structure of tables. I also need to avoid situations incase the server may be down, this proc should not return errors.
I'm having problem with an OpenQuery statement in stored procedure, which should be run on FoxPro linked server. I'm getting either an error messages or not the result I expected. I know that the problem is with WHERE part, without this part it works.
Here is the code: ------------------------------------- DECLARE @LastDate datetime SELECT @LastDate = MAX(DateChaged) FROM tblPersonel WHERE ACTIVE IN( 'A', 'T')
1. I tried: SELECT * FROM OPENQUERY(FoxProLink, 'SELECT ACTIVE, EmpNumber FROM tblPersonel WHERE DateChanged >=''+@LastDate+''')
This line gives me an error msg:
Could not execute query against OLE DB provider 'MSDASQL'. [OLE/DB provider returned message: [Microsoft][ODBC Visual FoxPro Driver]Operator/operand type mismatch.]
2. I tried to use CTOD() - FOXPRO function to convert character to date.
SELECT * FROM OPENQUERY(FoxProLink, 'SELECT ACTIVE, EmpNumber FROM tblPersonel WHERE DateChanged >=CTOD(''+@LastDate+'')')
-this doesn't give any error, but doesn't limit the result set as it should.
I have a parent package that contains two children... The second child depends on the succes of the first child.
THe first child generates a variable value and stores it in an Environment variable ( Visibility - All ) ...After the first succeeds, the second will start executing and will pick up the variable value from environment variable( through package configuration setting )...
Unfortunately, this doesn't work...As the second child picks the stale value of the environment variables...Essentially it assigns variable value not after the first child is finished, but right at the beginning of parent execution...
I tried to execute coth children as Out Of Proc as well as In Proc...The same
Would anybody have an idea how to resolve this problem?
Hi, This is pretty simple but I am doing somethin really stupid somewhere, I am trying to pass a value to a variable declared in a package using some SQL code, I declared a variable "var1" and assigned the scope to the package , then I dropped a execute SQL task within the package and wrote a simple sql code that would get the maximum id from a table, "select max(id) from table" , now I want to assign the variable this max value.so in the parameter mapping tab I select the variable give it a parameter name of 0 and size of -1 along with direction of "output". everythin looks simple but when I try to use this variable value in my next execute sql task it behaves weirdly, I am trying to update anothet table using this variable value, so I add another task and put this code in there " update table2 set id = ? " , and on the parameter mapping tab I set the direction as input, however when I look at the column it updated th column with a weird number , xomethin like "230072408" which doesnt mean anything. I know that tha max value of ID is 10. Please help.
Hi All, Would somebody be able to help me from pulling my hair out!??I have a form with a radiobuttonlist. I would like to change my select statement depending on what radiobutton value is selected.E.g.SELECT * FROM table WHERE <<variable from radiobuttonlist>> LIKE 'Y'So,if radiobutton value selected = 1, it will select * from column A in the dbif radiobutton value select = 2, it will select from column B in the dband so on... Am i attempting to do the impossible?Thanks All,
Hello, I have a SP that recevies a date value for a users date of birth called "dob". However when passing it into the class which contains the Stored procedure it gives an error. Below is my code please advice Thanks Ehi
HERE IS THE ERROR MESSAGE Compiler Error Message: CS0103: The name 'dob' does not exist in the current context
Source Error:
Line 40: command.Parameters[2].Value = "First_Name"; Line 41: command.Parameters[3].Value = "Last_Name"; Line 42: command.Parameters[4].Value = DateTime.Parse(dob.Text); Line 43: Line 44: int i = command.ExecuteNonQuery();
I am trying to get data from a database through a select statment and I want to pass the return query to a c# string variable. Any idea how can I do this?
could anyone please help me to resolve this issue? here's my sql query which retrieve last 3 month data t.execute(SELECT * tbl1 where nmonth >= datepart(mm,DATEADD(month, -3, getdate())) or nmonth <=datepart(mm,getdate()) and empno='"+emppip+"'") now instead of passing 3 in this query(datepart(mm,DATEADD(month, -3, getdate())) ) i need to pass a variable to retrieve data based on user requirements. i tried this way, dim mno as n mno=4 t.execute(SELECT * tbl1 where nmonth >= datepart(mm,DATEADD(month, -'"+mno+"', getdate())) or nmonth <=datepart(mm,getdate()) and empno='"+emppip+"'") its not working. can i achieve this using stored procedure? or can i directly pass a variable to sql synatax? thanks for any help
hi there, i am trying to pass a string which contains a string, here is the code which is wrong : {string sqlcommand = "select pnia.pnia_number, pnia.user_name, pnia.date_pnia, pnia.user_pnia, problem.problem, gormim.gorem_name, status.status_name from pnia,gormim,problem,status where (pnia.status='@p1' and status.status='@p1' and pnia.problem=problem.problem_num and pnia.gorem=gormim.gorem)"; OleDbCommand cmd = new OleDbCommand(sqlcommand,con);OleDbParameter p1 = new OleDbParameter("@p1",this.DropDownList4.SelectedItem.Value.ToString()); cmd.Parameters.Add(p1); } the problem is that the sql compailer doesnt take the parameter (@p1) as a string if someone could help me with that it would be great ! tnx
hi guys what is the syntax for using the passing variable part into the name of a table in a store procedure. in particular: (assume already declared the variable periodseq.
select * into Temp_Usage_@periodseq from Master_usage where Master_usage.PERIODSEQ = @periodseq
in particular the Temp_Usage_@periodseq line of code, how do i "add" the periodseq (which is a number) to the end of the name of Temp_Usage, i.e: Temp_Usage_112 is the syntax an & like Temp_Usage_&@periodseq? Cheers Champinco
I've been coding a few years and SSIS makes me feel more stupid than any program I've ever used. I've read BOL and bought a book. Can't say either one has really helped.
I'm still a complete idiot after one week of working with it. I apologize for asking so many stupid questions.
What I'm trying to do now is parameterize a SQL statement.
I have a variable that's a string. I have a DataFlowComponent as a data source. I find references all over the Internet and this forum to something called an "ExecuteSQLTask" but I sure can't figure out what that is. In my toolbox I have data flow sources for DataReader, Excel, Flat Files, Old DB, Raw file, and XML but no Execute Sql Task.
Anyway SELECT * FROM TABLE WHERE COLUMN='Value' in the SQL Command property is simple enough. Now I want 'Value' to be a variable. You know, like in T/SQL DECLARE @Foo VarChar(25). Creating the variable is easy as pie.
I have found at least 10 different examples of specifying variables on the web, all of which claim to be SSIS examples, Is it User::Variable? @[User::Variable]? @Variable?
I want to read rows from a table, with a a variable value in the WHERE clause, and pass them to the fuzzy lookup task.
Hi I am extracting data from Oracle via SSIS. There are three smilar schemas from where the data has to be extracted. Say My query is " Select * from abc.dept" where abc is the schema name. I want to pass this schema name through a variable and it should loop as there are total 3 schemas. There is a table which provided list of schemas. Can somebody please guide me how to do this. There are multiple references of this table is SSIS package.
I am running a query in with my daily import job that lets me know if a duplicate record was imported into the system. If so I want to setup my email table to mail me the following information. My code works fine except the value of the variable @ID is only giving me the first record in the set. How do I pass it on to the next record? I get the right number of rows inserted into the email table but the @ID variable is the same for all 3.
Drop Table #SER1
Select id#,
Colx=Count(*)
Into #SER1
From Business
Group By id#
Having Count(id#) > 1
Declare @ID Varchar (4)
Select @ID = ID# from #SER1
INSERT INTO Email
( [To],
[Subject],
[message],
[Table],
TableUKey,
TableSource
)
SELECT
'Firstname.Lastname@Company.com',
'Duplicate ID# Imported',
'ID# ' + @ID + ' has been imported multiple times ' + ' on ' + cast( getdate() AS varchar(30)) + '. You need to remove the record and rerun the import.',
I can't figure out how to pass values from report parameters to a variable in custom code. I have a Report Parameter called Parm1 of type string. It contains the following:
Label: Value: Labell1 Value1 Label2 Value2
In custom code I have declared a variable thus: Public Dim ParmValue As string = Parameters!Parm1.Value
What I want is this: When a user select a report, they will have to choose a parameter from a dropdown-list (created automatically when creating a paramete). The chosen parameter will be passed to the variable ParmValue which I use as one of the parametes in a text-box like this: =code.InstanceName.MethodName(ParmValue)
InstanceName is the instance of a class from a dll I reference. It works fine if I hard-code the paramter like this: Public Dim ParmValue As string = "SomeString" instead of: Public Dim ParmValue As string = Parameters!Parm1.Value
The error I get is this: [rsCompilerErrorInCode] There is an error on line 0 of custom code: [BC30469] Reference to a non-shared member requires an object reference.
I don't know if I'm at all on the right track here. Can someone tell me what I'm doing wrong?
I'm not an expert with using batch files, or using them with SSIS, but I am trying to use two batch files in my SSIS package. I want the first one to map the first available drive on the server and pass that drive letter as an output variable to the package, and then to pass this variable to the last batch file and unmap.
I already have execute program tasks set up with a hardcoded drive letter, but that is not going to work as I don't know what drive letters will be mapped on this machine.
I did find sample code for using variables in a batch file that maps drives:
Code Snippet @ECHO OFF
rem Map \serverfolder to the next available drive letter and save the driveletter as DRIVELETTER FOR /F "tokens=2" %%A IN ('net use * \serverfolder) DO IF NOT % %A.==command. SET DRIVELETTER=%%A
rem Unmap DRIVELETTER net use %DRIVELETTER% /del
rem Clear your env variables set DRIVELETTER=
Questions: 1. Is this the type of code I want to use with the SSIS package? 2. How do I use the batch file with SSIS? I see the Execute Process Tasks has a "StandardInputVariable" and "StandardOutputVariable". Will these work?
I have cursor that loops through a table (the table only contains columnnames of several tables) the cursor has a variable declared @columnname. when i run the following it works fine
now i want to get the min of each column name like so
select @columnname,min(mtr_5120),0,0,0 from temp_prt ------> this works for min(mtr_5120) mtr_5120,34.5,0,0,0
now I want to generalize so I try to pass in the variable name and I do the following
select @columnname,min(@columnname),0,0,0 from temp_prt (the columname (@columnname) exists in the table temp_prt)
but now i get an error Msg 8114, Level 16, State 5, Line 29
Error converting data type varchar to decimal.how can i pass the colunmame into the min and max functions or is that at all ppossible. I also tried the following:
select @columnname,'min(' + @columnname + ')',0,0,0 from temp_prt
but i get the same error Msg 8114, Level 16, State 5, Line 29 Error converting data type varchar to decimal.
I'm have created a data flow that uses an OLEDB source with a SQL Query. In the WHERE statement of this query is a condition for the storecode. I want to figure out how to create a loop that will cycle through a list of storecodes using a variable which is passed to the dataflow in turn to the OLEDB source's query and runs through the process for each store.
The reason i'm using a loop is because there are about 15 million records that are merge joined with 15 million others which is causing a huge performance problem. I'm hoping that by looping the process with one store at a time it should be faster. Any ideas would be greatly appreciated.
I am trying to exectue SQL task as below by passing a parameter
If I try....
@v1 datetime
set @v1 = convert(datetime, ? ,103)
it fails with below error
" failed with the following error: "Syntax error or access violation". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.
however the below code works well
delete from t1 where last_update = convert(datetime, ? ,103)
Is there anyway to pass data from a sql database to a variable in a ssis package. I'm trying to get a few fields from a sql database into some variables in my package and send an email using these variables with the send mail task?
Hi everyone I am new to this site I have a major issue I cant figure out seeing how im fairly new to asp, and vb, but i have 5 years php mysql experience. Im pulling the correct data into a grid. Then i need to make a button or some sort of link that will take the value of one field in the record set and replace it with @transid in the where statement I can enter in the value of transid into form field with that name and it will run the rest of the script correctly, I just cant get past this hurdle. If anyone can help that would be great. I tried to get this to work with java script but then realized thats not possible to transfer varaibles to asp from it. ///javascript function DisplayReciept(transactionnum) { recieptdis = transactionnum;