SQL Command From Variable In OLE DB Source

Apr 10, 2008

Using Jamie's, John's and Rafae post i have got this far.
My scenario demands me to do an incremental load. So i have followed your article and have created a one variable 'vDate' (Dataflow Task, Datetime, 3/3/2008) and another variable SourceSQL (Dataflow Task, String). I have set this SourceSQL evaluation to True and have added this;
"select * from stagingperfdata where startdatetime = "+ (DT_WSTR,10) @[vDate].

I want to call this within a OLE DB source, so i select the data access method to SQL command from variable. My variable name is visible and i am able to select it and then save and debug. I also have a derived column transformation to increment the variable vDate by one day.
The flow is successful but there is no records written to the target.
I tried the same query (available in the variable's value column) in SSMS and it is retrieving 12 records.
I went back to the Ole Db source and wanted to preview the data, but i get "Query timeout expired (Microsoft SQL Native Client)" error.
Am i missing something fundamental?

View 7 Replies


ADVERTISEMENT

OLE DB Source, SQL Command From Variable

Apr 15, 2008

I read several posts on this topic and I would like to confirm my understanding.

This question has to do with parameterizing the select statement in the OLE DB Source editor. Initially, I thought I could use Data access mode: SQL command, and somehow use a user variable in there to build my Select statement.

But in researching further, it looks like I need to store the entire SQL command in a one long string variable (let's call it A), where A is built off of another variable that has my parameter. I then use A in Data access mode: SQL command from variable.

Am I correct? And is there not a way to accomplish the samething with only one variable that is your parameter value?

It seems a bit clumsy to store the entire SQL expression in a string variable.

View 10 Replies View Related

SSIS OLE DB Source SQL Command From Variable DataType Problem

Sep 12, 2006

Hi,

I have to read data from an MDB file into SQL Server. Simple, but I need to place a literal into every row. In my OLE DB Source I would use:

SELECT '001' AS col1, foo, bar FROM Table1

But the problem is that I pass my value for col1 into the package from C# using Managed DTS.

So I set up my OLE DB Source using "SQL command from variable." And I have two variables one to receive the value of for col1 (col1) and one that is an evaluated expression that has a dynamic sql statement (dynSql).

col1 is a String as is dynSql. dynSql looks like this:

"SELECT " + @[col1] + " as col1, foo, bar FROM Table1"

Now as long as I set the value of col1 to '001' that should work. Right? Well not exactly. The destination for col1 in SQL Server is a char( 3 ). But the package makes the col1 column from the source a DT_WSTR. Which causes the famed: "Text was truncated or one or more characters had no match in the target code page.".

Is there a better solution?

Thanks. Kenneth.

View 1 Replies View Related

Using A Variable In SSIS - Error - Command Text Was Not Set For The Command Object..

Nov 4, 2006

Hi All,

i am using a OLE DB Source in my dataflow component and want to select rows from the source based on the Name I enter during execution time. I have created two variables,

enterName - String packageLevel (will store the name I enter)

myVar - String packageLevel. (to store the query)

I am assigning this query to the myVar variable, "Select * from db.Users where (UsrName = " + @[User::enterName] + " )"

Now in the OLE Db source, I have selected as Sql Command from Variable, and I am getting the variable, enterName,. I select that and when I click on OK am getting this error.

Error at Data Flow Task [OLE DB Source [1]]: An OLE DB error has occurred. Error code: 0x80040E0C.
An OLE DB record is available. Source: "Microsoft SQL Native Client" Hresult: 0x80040E0C Description: "Command text was not set for the command object.".

Can Someone guide me whr am going wrong?

myVar variable, i have set the ExecuteAsExpression Property to true too.

Please let me know where am going wrong?

Thanks in advance.








View 12 Replies View Related

XML TASK XSL Variable: Exception 'Property New Source Has No Source Xml Text'

Dec 20, 2005

Hi,
I want to transform an xml flow to an html flow. For this, I create an XmlDataDocument, I add on it, all that I want, and I store it in a file (in a dataflow task).
After that, in an xml task, I set the input properties like that:
Operation type: xslt
SourceType: File connection
Source: ras.xml
 
All works fine. But now, I want to use a variable to store my xml data. So, instead of storing my data in ras.xml, I store it in a variable like that:
 
Dim v As Microsoft.SqlServer.Dts.Runtime.Wrapper.IDTSVariables90
Me.VariableDispenser.LockOneForWrite("RAS", v)
v("RAS").Value = doc.OuterXml
v.Unlock()
 
and in the xml task, I set configuration like that:
 
Operation type: xslt
SourceType: Variable
Source: user::RAS
 
But when I execute, I got this following exception:
 
Error: 0xC002F304 at Format HTML Mail, XML Task: An error occurred with the following error message: "Root element is missing.".
Error: 0xC002928F at Format HTML Mail, XML Task: Property "New Source" has no source Xml text; Xml Text is either invalid, null or empty string.
 
Furthermore, when I want to debug it, in replacing the xml task, by a script task, I can see that in my RAS variable, I get the xml data which is well formed.
 
<?xml version="1.0" encoding="UTF-8"?>
<root> €¦
</root>
 
(When I store it in a file, I can see it in IE)
 
Have you got an idea ?
 
 
 
 

View 3 Replies View Related

OLE DB Source &&amp; SQL Command

May 3, 2006

Hi,

I am trying to set the OLE DB Source Editor. I am using the following option for Data Access mode

SQL Command from a variable and uses my sqlQuery variable.

sqlQuery variable contains a sql statement but I am getting the following error

ox80040E0C, Command text was not set for command object,

Additional information HRESULT 0xC0202009

Does it mean I have to give the variable name containing the stored procedure?

Please Guide

View 2 Replies View Related

How To Pass Parameter Into Source SQL Command?

Nov 15, 2007

Hi all,
I want to pass a parameter into my OLE DB source. For eg, I want to set the condition
SELECT * FROM "tablename" where ID = parameter  <-----------------
I do not know how to do this? can it be done by using package variable?

View 2 Replies View Related

SSIS SQL OLE DB Source - SQL Command Vs Mapping

Oct 10, 2007

I created a Stored Proc to compute all the data I need to export to a CSV file.
I use the provider MS OLE DB Provider for SQL Server.
It's a very simple package with a single Data Flow Task.
This flow task is using an OLE DB Source to call a simple SQL Command : Exec MyStoredProc.
There are no params.

This Stored Proc is using table variables to compute the data.
It takes about 10 seconds to return anything.
The problem is that the mapping doesn't work with the OLE DB Source.
There are no fields at all shown in the mapping screen.

I tried to replace the Stored Proc by a version which only returns fields and no data.
Then the mapping would work just fine.
The package is then compiling and working fine.
But everytime I put back the real stored proc, even without changing the SQL Command, the SSIS execution breaks at execution.
It keeps saying :

"Error: 0xC0202005 at Data Flow Task, OLE DB Source [477]: Column "RecordType" cannot be found at the datasource."

My guess is that SSIS doesn't wait the 10 secs and thinks the Stored Proc is not returning anything.
What can I do to make this work ?


Thanks,

Vincent

View 3 Replies View Related

How To Create A Dynamic SQL Command For OLE DB Source

Mar 21, 2008

Hi All,

I have a requirement to create a dynamic SQL Command in an OLE DB Source due to the fact that I need to read data from another database based on a date range. For example, the SQL command would look like

SELECT * FROM Table1 WHERE DateField BETWEEN '17/03/2008' and '21/03/2008'

and I need to change the dates - '17/03/2008' and '21/03/2008' to different dates when the package is deployed in production, how do I do that ?

Regards
Ash

View 12 Replies View Related

SQL Command From Variable

Mar 2, 2008

I'm having difficulty passing a date parameter in a SSIS OLEDB connection to a stored procedure using SQL command with the error message "Attempted to read or write protected memory ..." and if I create a variable, I get the error "must declare the scalar variable..". Here is the OLEDB command: "EXEC dbo.mic_TGDrop ?" where ? requires a date parameter @ReportDate. Why does the call to the stored procedure fail? What would be the correct syntax of a variable to use SQL Command from variable? The SQL BOL does not cover this; is there another resource that has a simple example? Thanks.

View 2 Replies View Related

Command USE With Variable

Mar 29, 2006



Why I can´t use the command USE with variable?

declare @banco varchar(20)
select @banco='xpto'
USE @banco

I have try in other way without success

DECLARE @banco varchar(50)
declare @SQL varchar(50)
select @banco='xpto'
print @banco
select @SQL='USE '+@banco
print @SQL
exec(@SQL)

Help me, please.



Rodrigo









View 7 Replies View Related

SQL COMMAND FROM VARIABLE

Oct 21, 2007


KEEPS SAYING MISSING EXPRESSION:

IN THE VARIABLE EXPRESSION I'VE WRITTEN THE FOLLOWING COMMAND:

"SELECT * FROM MY_TABLE WHERE T1.DATE >= @[USER:ATE]"


I'VE CLICKED EVALUATE EXPRESSION AND IT ACCEPTS THE EXPRESSION

HOWEVER WHEN I GO TO DATA FLOW TO SELECT SQL COMMAND FROM VARIABLE IT BRINGS BACK MISSING EXPRESSION????

View 13 Replies View Related

OLE DB Source - Data Access Mode - SQL Command

Feb 14, 2006

I got a package with data flow task. Within the data flow task I have flat file with Fiscal Calendar defined. I got another data source within the data flow task, which is OLE DB Source. I want to use SQL Command as data access mode. SQL similar to one the below is in there.

----------------------------------------------------------------------------------------------------

DECLARE @startdate DATETIME
DECLARE @enddate DATETIME
DECLARE @date DATETIME
DECLARE @id INT

SET @startdate = '1993-09-26' --Change these to
SET @enddate = '2010-09-25' --whatever you want
SET @id = 1
SET @date = DATEADD(dd, @id, @startdate)

WHILE @date <= @enddate
BEGIN
select @date CalendarDate,
DATEPART(dd, @date) CalendarDayMonth,
DATEPART(dy, @date) CalendarDayYear,
DATEPART(dw, @date) CalendarDayWeek,
DATENAME(dw, @date) CalendarDayName

SET @id = @id + 1
SET @date = DATEADD(dd, @id, @startdate)

END

----------------------------------------------------------------------------------------------------

This SQL works fine in SSMS and returns around 6000 rows. But when I plug the same SQL in OLE DB Source it returns only the first record. It is not going through the WHILE loop.

Has anyone came across this?

Thanks

Sutha

View 2 Replies View Related

OLE DB Source Executing SQL Command Multiple Times

Jan 2, 2008



Happy new year everyone!!!


Ok, now for my not so happy new year problem ... here's the scenario:

I have a simple task of exporting data retrieved by a parameterized stored procedure to a delimited text file ... task done in 30 mins max using dataflow task from OLE DB Source with SQL Command to Text File Destination ... thank you very much SSIS!

But the problem is the OLE DB Source executed the SP MULTIPLE TIMES (3 to be exact)
Actually configuration is:

1. OLE DB Source
2. SQL Command access mode
3. The following command written in the command text box:

SET FMTONLY OFF;
exec sp_SampleSP @param1=?, @param2=?
4. Configured parameter mapping.

The stored procedure logs to a database table everytime it is executed to report how many rows were selected (please don't crucify me with this method, i'm re-using procs from old system). The log shows that during execution of this package the SP was executed on 3 times.

Help anyone? Please ...

View 5 Replies View Related

Using A Variable In OLE DB Destination SQL Command

Nov 14, 2007

Hi all,
 I have created a global variable and it will read the user input from a web application. How can i pass this variable into OLE DB destination SQL command so that i can retrieve the user specified table? Or is there a better way to do this?

View 4 Replies View Related

How Can A Variable Used In SQL Select Command

Nov 8, 2004

select * from TABLE where user='jacky' ,it can working,but if like this:
dim name as string="jacky"
select * from TABLE where user=name
it won't doing,Can a variable used in SQL select command,if can,how to make it working.

View 2 Replies View Related

Using Variable String In Sql Command

Dec 5, 1999

Using SQL Server 7.0, I am trying to use a variable string called from a form to perform a simple query.

Here's what it looks like:

[after submitting a form on the previous page with a drop down list box titled "fiscal"]

dim strYear

strYear = Request.Form("fiscal")

sql = "SELECT * FROM VENDOR WHERE STATUS = 'P' AND '"& strYear &"';"

[where strYear is the following: PYMNT_DT > ''12/31/98'']

Records exist that meet this criteria. If the PYMNT_DT > '12/31/98' is hardcoded into the sql statement, 12 records are returned. However, when the variable string is used instead, no records are found. Any ideas on how this problem might be fixed?

Thanks in advance.

Sincerely,

Chad Massie

View 1 Replies View Related

Creating SQL Command From Variable

Apr 29, 2008

This is a really simple question. When I set my variable (the one will hold my SQL Command) property "EvaluateAsExpression=True", I don't get the option to edit the expression, I was expecting to get a little button that would open the "Property Expressions Editor" if pressed.

Am I doing anything wrong? Should I edit my SQL Command somewhere else and then Copy+Paste on my variable expression?

I need to pass a ServerName as a field to my query and I'm doing that by looping through a list of servers...

View 9 Replies View Related

Can't Set Variable Through Command Line

Mar 29, 2007

Hello everyone!

Bit of a problem executing a DTS command from a command line.

I have the following variables defined in my package:

UserVarchar1
UserVarchar2
UserVarchar3

All have a scope of Package, all of the mstrings

The command I'm attempting to run in 1 line is:

DTEXEC /FILE "C:SSIS PackagesED-CustomersPackage.dtsx"
/SET Package.Variables[User::UserVarchar1].value;"10"
/SET Package.Variables[User::UserVarchar2].value;"30719"
/SET Package.Variables[User::UserVarchar3].value;"BILLTO"




Description: The package path referenced an object that cannot be found: "Package.Variables[User::UserVarchar1].value". This occurs when an attempt is made to resolve a package path to an object that cannot be found.


DTExec: Could not set Package.Variables[User::UserVarchar1].value value to 10.

Any idea why?

Thanks for the help!

View 10 Replies View Related

SQL Command From Variable - Datetime

Nov 16, 2007

I was not able to find the solution myself so here I am to ask you.

I'm using an Ole DB Source with the SQL command from variable.

My variable expression needs to look like this:

select * from dbo.fx_function (SomeDateVariable)

My sql server fx_function recieves as a parameter datetime, my variable SomeDateVariable is datetime type.

I tried all different types of cast on @User :: SomeDateVariable but I either can't evaluate the expression or I have errors trying to execute the package.

Any ideas how the expression should look like?

I'll keep trying...

View 8 Replies View Related

Sql Update Command With Variable As ColName

May 7, 2008

Hello All
 I m trying to update a table whose col name will be read from another table.
For e.g. Table1 gives the result:
'emp1',   1,   'John'
'emp2',   2,   'Mike'
Now in the second table, i need to update the table with Col name  = 'Emp1' and then from the second row (above), I need to update Col name= 'Emp2'
I need to write one Update Statement which will handle all the cases. I tried
Update Table2 set @VariableName = .......
but didnt work...
How can i do that ?

View 7 Replies View Related

Sql Command From Variable, List Empty

Apr 7, 2008

Hello.

I created a package scope variable to use as a sql command for a data
flow task. But when I click the drop down to select it, nothing
appears. Anybody else have this issue and find a solution?


Thanks,
Rich

View 2 Replies View Related

Use Variable As IN List For OleDB Command

Sep 27, 2007

Group,

First let me say that I'm new to SSIS, so be gentle with me.

I need to extract a limited set of data from a very large view in Oracle (I know, yuk!). The view contains millions of rows, but I only need the child matches of 343 unique keys in a one to many relationship. In pure SQL the query would look something like this.

Select proj, tn, rn, total FROM Oracle.view WHERE proj in (select distinct proj from MSSQL.dbo.projlist)

As you can see, this is an impossible query on many levels.

My first thought was to get the runtime list into a variable and use that variable as a parameter in the Oracle OleDb Source. Alas, the Oracle source will not allow me to add a parameter.

My second thought was to use a script component and build a SQL_Command string into a variable with all of my keys included. Then use the read_write variable as the SQL Command from variable in the Oracle Source. My attempts to construct such a variable expression have failed.

Any ideas would be appreciated.


RH

View 11 Replies View Related

How To Add Variable To Sql Command Text Field

Sep 7, 2007

In the data flow task I have multiple OLE DB source task to retreive data from a cube using MDX. Below is an example of the query from sql command text field: I have a few questions on how to modify this statment to make it more robust.

1) The where clause [Calendar].[Quarter 2 (2007)] should actually be some kind of variable that will change each time
the user runs this project. So I am wondering how to make this a variable and get it into this field.

2) I had thought that I could use the SSIS variable. I have created one, but I can not figure how to get it into the field that
contains the given select statment.

3) I believe that once I get this variable part to work then I want a way to have user set this data value. Either by selecting data from a table in database or through a user interface where user enters data. I did do some resarch on creating a user interface, but I did not understand what I had to do, so if any one knows where to find a tutorial on how to do this let me know, or what they believe the best/easiest way is to get data from user to fill this where clause.
select * from OPENROWSET('MSOLAP', 'DATASOURCE=local; Initial Catalog=Patient Demographics 2005;',
'with member [Measures].[TimeDisplayName] as [Calendar].CurrentMember.Name
SELECT NON EMPTY { [Measures].[TimeDisplayName],[Measures].[Adjusted Relative Weight],[Measures].[Adjusted Case Weight]} ON COLUMNS,
({[Facility].[REGION].[NATCODE], [Facility].[REGION].[REGCODE]} *
[RIC].[CMGGRPCD].ALLMEMBERS) ON ROWS FROM [ESR]
WHERE [Calendar].[Quarter 2 (2007)]
')

View 10 Replies View Related

Integration Services :: Using Database Name As Parameter In OLE DB Source Command Text?

Aug 6, 2015

I'm using following command to populate my OLE DB Source. I have two of those in each Data Flow in my package. One of the OLE DB Sources points to my source database the other to the destination. In order to limit the number of rows I use the WHERE clause below. The [EnergyMiserFSRLive] being the the name of the source database. The Connection manager points to the destination database.

I would like an elegant way to replace  [EnergyMiserFSRLive] with a parameter which I can reuse in each of my many data flows rather than use this hard coded value [EnergyMiserFSRLive].In particular I'm after the syntax of the below query that uses the parameter for [EnergyMiserFSRLive].

SELECT [SitesId]
      ,[SiteName]
      ,[FilePrefix]
      ,[City]
      ,[StateProv]
      ,[Country]
  FROM [Sites]
WHERE SitesId >= (SELECT MIN(SitesId) FROM [DBNameFSRLive].[dbo].[Sites])
  ORDER BY [SitesId]

View 5 Replies View Related

Passing '% Variable %' To SqlDataSource Through E.Command.Parameters

Feb 23, 2008

 Hello all,I'm writing a site with one page that uses the session variable (User ID) to pick one user ID out of a comma separated list in the field Faculty. The default parameterized query designed in the SqlDataSource wizard only returns lines that contain an exact match:SELECT * FROM tStudents WHERE ([faculty] = @faculty) The query: SELECT * FROM tStudents WHERE ([faculty] LIKE '%userID%') works as I need when I hard code the query with a specific user ID into the SqlDataSource in the aspx page.  It will not work if I leave the @faculty parameter in it:SELECT * FROM tStudents WHERE ([faculty] LIKE '%@faculty%') e.Command.Parameters works to replace the @Faculty with a user ID, but again, adding the single quote and percentage sign either causes errors or returns no results.  I've tried several variations of:         string strEraiderID = "'%" + Session["eRaiderID"].ToString() + "%'";        e.Command.Parameters["@faculty"].Value = strEraiderID;no results are returned, not even the lines returned with the default select query.How do generate the equivalent of SELECT * FROM tStudents WHERE ([faculty] LIKE '%userID%') into the SqlDataSource? Thanks much! 

View 3 Replies View Related

Storing Variable In Command File From SQL Server

Sep 13, 2004

Hi,
i am using command files(.cmd) and osql utility to conneft to a database.
following is the requirement.
I have a query "SELECT top 1 au_fname FROM pubs..authors".

Can i store the value of au_fname in the command file?

Is there any work around for this.

Any help is appreciated.

Thanks.... :)

View 1 Replies View Related

How To Add A Variable In 'Source' View ?

Mar 17, 2007

There are 3 views in VS IDE, Designer, Code and Source. In source view, there are html codes, how do I add a variable into it ? For example: <asp:SqlDataSource ID="SqlDataSource1" runat="server"                     ConnectionString="<%$ ConnectionStrings:JJConnectionString %>"                    SelectCommand="SELECT * FROM [Tbl]" ... How to change the SelectCommand to like:SelectCommand="SELECT * FROM [Tbl] WHERE [CREATEDBY] = '" & User.Identity.Name & "'" The User.Identity.Name is not valid in source view, but i need it to work, are there any way ? 

View 1 Replies View Related

Trouble Using XML Source From A Variable

Jun 14, 2006

I have a SP that outputs a valid XML record set. Using a Execute SQL
Task, I can put the XML results into a string variable. When I try to
use the variable in an XML Source nothing happens and I get no error..
If I access the same XML from a file, I get the desired results.



Any ideas why?

View 9 Replies View Related

Run Variable In DataReader Source?

Apr 7, 2006

Hi all,

I am trying to have a DataReader Source that can run
a variable which I used to store the SQL statement. For example, I have:



Variable #1

Variable name: tablename

Data Type: string

Value: "name_of_table"



Variable #2

Variable name: sql_stmt

Data Type: string

Value: "SELECT * FROM " + @tablename



I want to use DataReader Source to run Variable #2 in the SqlCommand
that connects to an ODBC connection. If it is possible by any way,
please let me know. Thanks in advance.



Daren

View 14 Replies View Related

Table Variable As A Source

Sep 26, 2007

Hi,

I am using a table variable as a source in my OLE DB Source task ( I declare and populate this table variable from TSQL script) to load data in my destination table however the data gets lost after the task, ie I can preview the data from the OLEDB Source task but when I go to the next task which is multicast tranformation the data is lost, I have used data viewers to see the data but they dont have any rows, any help is appreciated.

Thanks

View 18 Replies View Related

OLE DB Source Using Table Name Variable

Jan 22, 2007

I have a package-level variable [User::viewName], type = string, containing a view name. I want to setup an OLE DB source to use this variable value as the source, so Data access mode = "Table name or view name variable". The Variable name dropdown contains [User:viewName], so I select it. When I click OK to leave the edit dialog I get the error:

The variable User::viewName is required to be of type "VT_BSTR".

Only variables of type String occur in the Variable name dropdown; if I try changing it to a type other than string it doesn't occur in the dropdown. What is VT_BSTR and how can I change the variable type to it?

View 11 Replies View Related

Integration Services :: Will Exceeding Command Timeout On OleDB Source Fail Pkg

Jun 16, 2015

We run std 2008 r2.  I'm trying out the commandtimeout property of an oledb source.  I set it to 30 expecting 30 seconds.  if connection and or execution exceed that threshold, will the pkg fail?  Either way is there a way I can detect that the threshold was exceeded? 

View 3 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved