Showing posts with label store. Show all posts
Showing posts with label store. Show all posts

Friday, March 23, 2012

Run Variable in DataReader Source?

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
Use a property expression on the SqlCommand of the DataReader Source. Expressions for Data Flow components can be found on the Data Flow task itself. Select the Data Flow and open the VS Properties grid. Then select expressions.|||Hi Darren,
I still do not get how to use Variables in DataReader Source? Can you lead me to an example or show me a simple example on how to get it to work on AdventureWorks database.
Thank you.
Daren
|||

A variable can be used in an expression.

A variable can be an expression in so much as you can set the EvaluateAsExpression property to True, and the Expression property to an expression. The value of the variable will then be the evaluated expression result.

The DataReader source as a SqlCommand property, and that supports expresisons as well, this is called a property expression. If you don't know what this is, please look it up in Books Online. So the SqlCommand can be a literal, or an expression which itself can reference a variable. That variable can be set via EvaluateAsExpression as well.

These topics are well documented in Books Online. Try these for a start-

DataReader Source (http://msdn2.microsoft.com/en-us/library/ms137897(SQL.90).aspx) - "This source includes the SQLCommand custom property. This property can be updated by a property expression when the package is loaded. For more information, see Integration Services Expression Reference, Using Property Expressions in Packages, and Source Custom Properties."

Using Property Expressions to Specify Property Values for Data Flow Objects (http://msdn2.microsoft.com/en-us/library/ms136104.aspx)

|||Ok, thanks Darren. I am gonna try it out to see if it works...
Daren
|||Hi Darren,
Sorry to bother you again, for the following sentence:
So the SqlCommand can be a literal, or an expression which itself can reference a variable. That variable can be set via EvaluateAsExpression as well.
do you mean I can write expression in the SqlCommand? like "Select * from "+@.tablename? as this is how I write in the expression for a variable. If this is not the way to write it, can you show me an example on how to do it? because the online book is not helping much without any example.
Thanks in advance.
Daren
|||

I will tell you how I run expressions on my datareaders. I am by no means stating that the following is the best way, but it's the only way I know of and it works for me. If you have not already found the datareader expression box, which is definitely not placed intuitively given that most other expressions are found on the tasks themselves, do the following:
- Once inside your dataflow task, click on the workarea (to make sure you haven't highlighted anything within the dataflow)
- Look in the properties window (mine found on bottom right)
- Scroll down in your properties to the Expressions box, and click on the ellipses
- Once there, looking at the properties available in the drop down box you will see any datareader.SqlCommand that you currently have in your dataflow. From there click on the corresponding expression ellipses.
- Here is where you can set queries similar to the one you posted above.
Beware the expressions are very picky with data types if you haven't already found that out, so you'll have to use the casting terminology to cast variables to a string if they aren't already. Here's an example for you, where I'm casting variables that are of type DateTime:

"SELECT * FROM DATE_TBL WHERE DATE BETWEEN '" + (DT_WSTR, 30) @.[User::IVR_START_DATETIME] + "' AND '" + (DT_WSTR, 30) @.[User::IVR_END_DATETIME] + "'"

Hope this helps, I know the pain I went through finding out that datareaders could use expressions, especially back when there was little info available.

Adrian

|||

Adrian is right that you have to be wary of data types - its easy to get confused. Always remember that all you are doing when you are building your SQL statement is concatenating strings. So, make sure everything is converted to a string (i.e. DT_STR or DT_WSTR) before trying to concatenate.

Not sure I agree that the expressions interface isn't placed intuitively but I'll bow to Adrian's opinion on that one :)

-Jamie

|||Hi Adrian, sorry for this late reply, I was not around for the past few days doing something else. But thanks for the little guide of yours, it helps me a lot. Also I will take note on the data types there. Thanks again.
Daren
|||

Adrian, I have a similar cast of a DateTime variable to a string, but in attempting to get part of the date (for example, the Year), SSIS returns an invalid cast.

Example code: (DT_WSTR,4)YEAR(@.[User::DateToImport])

This evaluates perfectly in the Expression Builder, but upon running the project, the following errors are returned:

Error: The function "YEAR" does not support the data type "DT_WSTR" for parameter number 1. The type of the parameter could not be implicitly cast into a compatible type for the function. To perform this operation, the operand needs to be explicitly cast with a cast operator.

Error: The expression "(DT_WSTR, 4) YEAR(@.[User::DateToImport])" on property "ConnectionString" cannot be evaluated. Modify the expression to be valid.

So, there's a bit of a disconnect here somewhere...

|||What type is the variable User::DateToImport? The error says to me that it is String (DT_WSTR). It needs to be a DateTime.|||It is very much a DateTime type.|||

Take a read of this: http://blogs.conchango.com/jamiethomson/archive/2005/10/11/2261.aspx

It may be a pointer as to the problem. Basically there is bug that means a datatime variable can hold a value which isn't a datetime.

-Jamie

|||

Thank you Adrian.
I have been looking for this answer for about 2 weeks now. Your post was the only one that i have found that told me that i need to specify my variable in the Expression ellipses. I have been trying unsuccesfully to put my varaible in the [DataReader Source].[SQL Command] property.

Run Variable in DataReader Source?

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
Use a property expression on the SqlCommand of the DataReader Source. Expressions for Data Flow components can be found on the Data Flow task itself. Select the Data Flow and open the VS Properties grid. Then select expressions.|||Hi Darren,
I still do not get how to use Variables in DataReader Source? Can you lead me to an example or show me a simple example on how to get it to work on AdventureWorks database.
Thank you.
Daren
|||

A variable can be used in an expression.

A variable can be an expression in so much as you can set the EvaluateAsExpression property to True, and the Expression property to an expression. The value of the variable will then be the evaluated expression result.

The DataReader source as a SqlCommand property, and that supports expresisons as well, this is called a property expression. If you don't know what this is, please look it up in Books Online. So the SqlCommand can be a literal, or an expression which itself can reference a variable. That variable can be set via EvaluateAsExpression as well.

These topics are well documented in Books Online. Try these for a start-

DataReader Source (http://msdn2.microsoft.com/en-us/library/ms137897(SQL.90).aspx) - "This source includes the SQLCommand custom property. This property can be updated by a property expression when the package is loaded. For more information, see Integration Services Expression Reference, Using Property Expressions in Packages, and Source Custom Properties."

Using Property Expressions to Specify Property Values for Data Flow Objects (http://msdn2.microsoft.com/en-us/library/ms136104.aspx)

|||Ok, thanks Darren. I am gonna try it out to see if it works...
Daren
|||Hi Darren,
Sorry to bother you again, for the following sentence:
So the SqlCommand can be a literal, or an expression which itself can reference a variable. That variable can be set via EvaluateAsExpression as well.
do you mean I can write expression in the SqlCommand? like "Select * from "+@.tablename? as this is how I write in the expression for a variable. If this is not the way to write it, can you show me an example on how to do it? because the online book is not helping much without any example.
Thanks in advance.
Daren
|||

I will tell you how I run expressions on my datareaders. I am by no means stating that the following is the best way, but it's the only way I know of and it works for me. If you have not already found the datareader expression box, which is definitely not placed intuitively given that most other expressions are found on the tasks themselves, do the following:
- Once inside your dataflow task, click on the workarea (to make sure you haven't highlighted anything within the dataflow)
- Look in the properties window (mine found on bottom right)
- Scroll down in your properties to the Expressions box, and click on the ellipses
- Once there, looking at the properties available in the drop down box you will see any datareader.SqlCommand that you currently have in your dataflow. From there click on the corresponding expression ellipses.
- Here is where you can set queries similar to the one you posted above.
Beware the expressions are very picky with data types if you haven't already found that out, so you'll have to use the casting terminology to cast variables to a string if they aren't already. Here's an example for you, where I'm casting variables that are of type DateTime:

"SELECT * FROM DATE_TBL WHERE DATE BETWEEN '" + (DT_WSTR, 30) @.[User::IVR_START_DATETIME] + "' AND '" + (DT_WSTR, 30) @.[User::IVR_END_DATETIME] + "'"

Hope this helps, I know the pain I went through finding out that datareaders could use expressions, especially back when there was little info available.

Adrian

|||

Adrian is right that you have to be wary of data types - its easy to get confused. Always remember that all you are doing when you are building your SQL statement is concatenating strings. So, make sure everything is converted to a string (i.e. DT_STR or DT_WSTR) before trying to concatenate.

Not sure I agree that the expressions interface isn't placed intuitively but I'll bow to Adrian's opinion on that one :)

-Jamie

|||Hi Adrian, sorry for this late reply, I was not around for the past few days doing something else. But thanks for the little guide of yours, it helps me a lot. Also I will take note on the data types there. Thanks again.
Daren
|||

Adrian, I have a similar cast of a DateTime variable to a string, but in attempting to get part of the date (for example, the Year), SSIS returns an invalid cast.

Example code: (DT_WSTR,4)YEAR(@.[User::DateToImport])

This evaluates perfectly in the Expression Builder, but upon running the project, the following errors are returned:

Error: The function "YEAR" does not support the data type "DT_WSTR" for parameter number 1. The type of the parameter could not be implicitly cast into a compatible type for the function. To perform this operation, the operand needs to be explicitly cast with a cast operator.

Error: The expression "(DT_WSTR, 4) YEAR(@.[User::DateToImport])" on property "ConnectionString" cannot be evaluated. Modify the expression to be valid.

So, there's a bit of a disconnect here somewhere...

|||What type is the variable User::DateToImport? The error says to me that it is String (DT_WSTR). It needs to be a DateTime.|||It is very much a DateTime type.|||

Take a read of this: http://blogs.conchango.com/jamiethomson/archive/2005/10/11/2261.aspx

It may be a pointer as to the problem. Basically there is bug that means a datatime variable can hold a value which isn't a datetime.

-Jamie

|||

Thank you Adrian.
I have been looking for this answer for about 2 weeks now. Your post was the only one that i have found that told me that i need to specify my variable in the Expression ellipses. I have been trying unsuccesfully to put my varaible in the [DataReader Source].[SQL Command] property.

sql

Tuesday, March 20, 2012

Run SP from UDF?

Hi,
Is it possible to run a Stored Proc from a UDF?
If it is possible, how do I store the resultset that the SP produces? The
code I have does not work, as I don't think you can use the EXEC keyword in
a
UDF but here it is anyway:
DECLARE @.tempMeterData TABLE (
RoundedTimestamp smalldatetime NOT NULL,
[Value] float NULL)
INSERT INTO @.tempMeterData EXEC sp_MySP @.ID
Any help on how I could achieve this would be gratefully received.
Thanks,
SteveAs you said, you can not call a stored procedure (you can call exteded ones)
inside a udf.
What are you trying to accomplish?
AMB
"SteveN" wrote:

> Hi,
> Is it possible to run a Stored Proc from a UDF?
> If it is possible, how do I store the resultset that the SP produces? The
> code I have does not work, as I don't think you can use the EXEC keyword i
n a
> UDF but here it is anyway:
> DECLARE @.tempMeterData TABLE (
> RoundedTimestamp smalldatetime NOT NULL,
> [Value] float NULL)
> INSERT INTO @.tempMeterData EXEC sp_MySP @.ID
> Any help on how I could achieve this would be gratefully received.
> Thanks,
> Steve
>|||I am updating an old UDF which is used widely in an ASP.NET application. Th
e
UDF returns a table, so it probably should be an SP, but that is a different
matter.
Data the UDF needs to return now (depending on parameters) is calculated in
an existing SP, so I want to be able to get the return data from that SP to
use in the existing UDF.
Any ideas on what I can do?
Thanks,
Steve
"Alejandro Mesa" wrote:
> As you said, you can not call a stored procedure (you can call exteded one
s)
> inside a udf.
> What are you trying to accomplish?
>
> AMB
> "SteveN" wrote:
>|||Replace the function with an SP or move the logic from the existing SP
into the function.
David Portas
SQL Server MVP
--|||What is the reason of returning this resultset using a udf an not calling th
e
sp directly?
Are you planning to do extra manipulation on the result of the sp?
How complicated is the process inside the sp?
AMB
"Steve Norman" wrote:
> I am updating an old UDF which is used widely in an ASP.NET application.
The
> UDF returns a table, so it probably should be an SP, but that is a differe
nt
> matter.
> Data the UDF needs to return now (depending on parameters) is calculated i
n
> an existing SP, so I want to be able to get the return data from that SP t
o
> use in the existing UDF.
> Any ideas on what I can do?
> Thanks,
> Steve
> "Alejandro Mesa" wrote:
>|||Further manipulation on the resultset will be done in the UDF before it is
returned as a table, the SP that is called is 367 lines and is very
complicated indeed.
I am trying to find an alternative to re-writing the UDF as a SP as there
are other UDF's that use this UDF as the core to their data manupulation, so
I would also need to re-write all of these as SPs.
If that is the only answer than that is what I will have to do, but I was
trying to save a couple of days of re-writing and testing by simply getting
data from an exisitng SP in a couple of lines of code.
Steve
"Alejandro Mesa" wrote:
> What is the reason of returning this resultset using a udf an not calling
the
> sp directly?
> Are you planning to do extra manipulation on the result of the sp?
> How complicated is the process inside the sp?
>
> AMB
>
> "Steve Norman" wrote:
>|||Steve,
Your working with .Net,
Run you sp and output the parameters then run your function from .net with
newly acquired params ?
"Steve Norman" wrote:
> Further manipulation on the resultset will be done in the UDF before it is
> returned as a table, the SP that is called is 367 lines and is very
> complicated indeed.
> I am trying to find an alternative to re-writing the UDF as a SP as there
> are other UDF's that use this UDF as the core to their data manupulation,
so
> I would also need to re-write all of these as SPs.
> If that is the only answer than that is what I will have to do, but I was
> trying to save a couple of days of re-writing and testing by simply gettin
g
> data from an exisitng SP in a couple of lines of code.
> Steve
> "Alejandro Mesa" wrote:
>

Monday, March 12, 2012

Run JS script from report

I have a report that shows product available for employees in the outlet
store. A person who is responsible to price product is asking me if it's
possible to enter prices in while he is looking at the report. I was
thinking to have a link on the report that will open a new window with a
simple form to enter price information and save it. Can I run JS script form
a report?
ThanksWhat you can do is use the jump to url action that opens up another web page
in another window.
This is something I used in RS 2000 when Excel rendering was slow, I don't
do this anymore but it shows you the syntax.
This causes Excel to come up with the data in a separate window:
="javascript:void(window.open('" & Globals!ReportServerUrl &
"?/SomeFolder/SomeReport&ParamName=" & Parameters!ParamName.Value &
"&rs:Format=CSV&rc:Encoding=ASCII','_blank'))"
Notice and be careful of the single and double quotes usage.
My suggestion is to start with a report with a single textbox. Right mouse
click on text box, properties, navigation tab. Hard code the URL string to
bring up a web page. Then hard code it to bring up the appropriate web page
passing the parameter (all hard coded). Next have a simple report and have
one of your fields with this action on it (I make the text blue and
underlined). Use the expression builder to get the value of the appropriate
field into your URL string.
Bruce Loehle-Conger
MVP SQL Server Reporting Services
"Mark Goldin" <mgoldin@.ufandd.com> wrote in message
news:OpZw7x4%23HHA.4828@.TK2MSFTNGP04.phx.gbl...
>I have a report that shows product available for employees in the outlet
>store. A person who is responsible to price product is asking me if it's
>possible to enter prices in while he is looking at the report. I was
>thinking to have a link on the report that will open a new window with a
>simple form to enter price information and save it. Can I run JS script
>form a report?
> Thanks
>

Wednesday, March 7, 2012

run access database too slow

I have a access database, the data store in another server. This noon, one of our user is runing the access database too slow. Open the database and search the data, etc. It took a long time to come out, Any body has experience on it, why, we had etrust install on each user machine, is that cause this too slow? Thanks in advance.Is it Access front-end or Access period? If the latter, - wrong forum, though you might get some answers if you're a little bit more specific.

Tuesday, February 21, 2012

rtf

I'm filling richtextbox with data.
I want to save it into database, but I don't know wich type of field shoul I
use in table to store that kind of data?Well, is there a limit to how much text people can enter into this
field? Also, do you anticipate that the amount of text entered will
vary a lot (e.g. some people will enter a little, some a lot and
possibly some could enter nothing)?
If people aren't allowed to enter more than 8000 characters then you
can use CHAR or VARCHAR data types. If the amount entered by people
could vary a lot then use VARCHAR and set the maximum size of the field
to the maximum number of characters you anticipate people entering. If
the amount people will enter does not vary much then use CHAR set the
maximum size of the field to the maximum you anticipate people
entering.
Anything larger than 8000 characters you should probably consider using
the "text" data type.
Hope that helps a bit.

rtf

I'm filling richtextbox with data.
I want to save it into database, but I don't know wich type of field shoul I
use in table to store that kind of data?Well, is there a limit to how much text people can enter into this
field? Also, do you anticipate that the amount of text entered will
vary a lot (e.g. some people will enter a little, some a lot and
possibly some could enter nothing)?
If people aren't allowed to enter more than 8000 characters then you
can use CHAR or VARCHAR data types. If the amount entered by people
could vary a lot then use VARCHAR and set the maximum size of the field
to the maximum number of characters you anticipate people entering. If
the amount people will enter does not vary much then use CHAR set the
maximum size of the field to the maximum you anticipate people
entering.
Anything larger than 8000 characters you should probably consider using
the "text" data type.
Hope that helps a bit.