Syntax For Passing A String To SelectCommand

Sep 15, 2007

 Hey,
I've inherited a project from my office and am stuck.

I'm trying to take input from multiple souces (DropDownLists, TextBoxes, etc) and depending on which ones are used, update a SELECT string with additional AND statements.

  <script language=VB runat=server>
Dim resultsql As String
Public Sub Button_Click(ByVal client As String, ByVal state As String)
Dim dv As String
resultsql = resultsql & "SELECT ClientName, Address1, City, State FROM tblClient"
dv &= ""
If (StrComp(client, dv) <> 0) Then
resultsql &= "AND ClientName = " & client
End If
If (StrComp(state, dv) <> 0) Then
resultsql &= "AND State = " & state
End If
resultsql &= " ORDER BY ClientName ASC"
End Sub
</script>
Now when I got to display the results of this new string in a GridView I am recieving errors trying to pass my variable "resultsql" into SelectCommand. <asp:GridView ID="Results" runat="server" AutoGenerateColumns="False" DataKeyNames="ClientNumber"
DataSourceID="SqlDataSource3">
<Columns>
<asp:BoundField DataField="ClientName" HeaderText="ClientName" SortExpression="ClientName" />
<asp:BoundField DataField="Address1" HeaderText="Address1" SortExpression="Address1" />
<asp:BoundField DataField="City" HeaderText="City" SortExpression="City" />
<asp:BoundField DataField="State" HeaderText="State" SortExpression="State" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:SQLConnectionString %>"
SelectCommand=resultsql> </asp:SqlDataSource> 

I've scoured the web without any success.
 
Any suggestions are appreciated.

View 7 Replies


ADVERTISEMENT

Syntax Problem For WHERE Part Of My SqlDataSource SelectCommand

Jun 6, 2008

I am setting the SelectCommand of the SqlDataSource in my page_load. This is the WHERE part of my SelectCommand:WHERE ProductName LIKE '%' ? '%' OR ProductRef LIKE '%' ? '%'The above uses two select parameters. But the two select parameters will have the same value. So is it possible to re-write my select command so it just uses one parameter? I have tried the following, but this doesn't work. WHERE (ProductName OR ProductRef) LIKE '%' ? '%'Is there similar syntax I could use that works?

View 2 Replies View Related

How To Pass String Into Sqldatssource Selectcommand?

Mar 13, 2007

Help!  I'm trying to figure out how to pass a string variable to my sqldatasource's "selectcommand" attribute.  I'm trying to construct my SQL dynamically to adjust some things.  My code is something like this, 
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="report.aspx.vb" Inherits="_Default"    EnableEventValidation="false" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><%@ Import Namespace="System.IO" %><html xmlns="http://www.w3.org/1999/xhtml"><head id="Head1" runat="server"></head><body style="font-family: Arial,Verdana; font-size: 8">    <%          Dim selectCommandVar as String = "select column from mytable"    %>
<form runat="server"> <asp:SqlDataSource ID="SqlChild" runat="server" ConnectionString="<%$ ConnectionStrings:mynnectionString %>"        ProviderName="<%$ ConnectionStrings:gmConnectionString.ProviderName %>" selectcommand="selectCommandVar">        </asp:SqlDataSource></form></body></html>
What's the best way to get the contents of my selectCommandVar variable into the SelectCommand attribute of my sqldatasource?  The above syntax doesn't work and I've tried several permutations that do not work either.  The examples of sqldatasource I keep finding have the SQL statement hardcoded in the <asp:sqldatasource> section, which won't work for me.  HELP!

View 10 Replies View Related

Syntax For Passing Variable-usp

May 20, 2007

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

View 1 Replies View Related

Insert Syntax When Passing Input Parameters

Dec 27, 2000

I'm trying something like this:

CREATE PROCEDURE Add_Junk @Dist char, @CheckNo int =null OUTPUT AS
Set NoCount On
BEGIN TRANSACTION
INSERT INTO Junk (Dist)
VALUES (@Dist)
COMMIT TRANSACTION
select @CheckNo=@@IDENTITY

If what I pass is "416" I only get the "4" in my database and nothing else.
I don't get an error message.
What is wrong with my syntax?

PS I'm using Microsoft SQL 7.0

View 2 Replies View Related

Passing A Variable To A Linked Query (OPENROWSET For Excel Syntax)

May 11, 2007

Hello,

I responded to a very old discussion thread & afraid I buried it too deep.

I have studied the article: How to Pass a Variable to a Linked Query (http://support.microsoft.com/default.aspx?scid=kb;en-us;q314520)



but I have not gotten all the ''''' + @variable syntax right.



Here is my raw openrowset with what I am aiming at.






Code Snippet

-- I want to use some kind of variable, like this to use in the file:

DECLARE @FIL VARCHAR(65)

SET @FIL = 'C:company foldersDocumentationINVENTORY.xls;'

--

SELECT FROM OPENROWSET('MSDASQL', 'Driver=Microsoft Excel Driver (*.xls);DBQ=C:company foldersDocumentationINVENTORY.xls;', 'SELECT * FROM [Inventory$]')

AS DT



Anyone game? Many thank-yous, in advance.



Kind Regards,

Claudia.

View 1 Replies View Related

Passing Xml String

Apr 27, 2004

Hi,
i m tring to pass my xml string to my sql server but i receive empty value even tho my xml have it's value.
here's my code,

insert user(userName)
select xml_user
from OPENXML(@xmlHandle,'/NewDataSet',1)
with (xml_user nvarchar(20) 'table/user_name')


my XML code
<NewDataSet>
<table>
<user_name>dorris</user_name>
</table>
</NewDataSet>

Please advice on this matter.Thanks

View 1 Replies View Related

Passing A String Variable To Sql

May 11, 2008

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

View 2 Replies View Related

Passing A String For IN Clause

Sep 26, 2004

Hello,

How do I pass a string parameter to a Stored Procedure with an 'in' clause?

ex.
Select * FROM Persons
WHERE PersonID IN (1,2,3,4,5,20,56,80)

How do I define my Store Procedure so I can pass the values between () as a string (nvarchar) parameter to the SqlCommand?

Thanks,
W

View 1 Replies View Related

Passing XML String To Stored Procedure

Nov 28, 2005

hi,i have a stored procedure that is used to insert the employee data into a EMPLOYEE table.now i am passing the employee data from sqlCommand.i have the XML string like this'<Employee><Name>Gopal</Name><ID>10157839</ID><sal>12000</sal><Address>Khammam</Address></Employee>' when i pass this string as sql parameter it is giving an error. System.Data.SqlClient.SqlException: XML parsing error: A semi colon character was expectedbut when i execute the stored procedure in query analyzer  by passing the same parameter. it is working.please reply me on gk_mpl@yahoo.co.in

View 1 Replies View Related

Passing String To Rdlc's TextBox

Jan 23, 2008



Hello
I am pretty new to reporting services. Now i have something like this. on the .cs file, i have a fullName lets say
String fullName = "John Smith",
Now I want to pass this string to the report's textBox and show this value on this textbox.

How can i do this?
1.How should i write in .cs file?
2. How should i set the expression for the textbox?

Thank you very much. It is very urgent! Please help!

View 6 Replies View Related

Solution To Passing Parameters With Sql Text String.

Dec 26, 2003

I thought I would post this solution. I searched a long time and didnt see anything about how to solve my problem. After avoiding this and simply building strings I decided to dig in my heels and try and figure this out. Well, maybe I am just slow. :) Anyhow, here is some code that should help a lot of folks with this question...


Function GetProductCategories(ByVal departmentID) As DataSet

'set the connection string (comes from a property in this case)
Dim connection As SqlConnection = New SqlConnection(ConfigurationSettings.AppSettings("ConnectionStringWeb"))

'set the sql text string notice the @DepartmentID is my parameter. protected from sql injections
Dim strSQL As String = "SELECT * FROM ProductCategory WHERE DepartmentID = @DepartmentID"

'set new command object to strsql and the connection. required
Dim command As New SqlCommand(strSQL, connection)

'set parameters to pass to through with the strsql. required for parameters. you can take this a set further. See commented fields below.
command.Parameters.Add(New SqlParameter("@DepartmentID", departmentID))

'additional set up for parameters if you like...
'command.Parameters.Add("@departmentID", SqlDbType.Int, 4)
'command.Parameters("@departmentID").Value = departmentID



'set SQLDataAdapter to your previously created command object
'this enables your adapter access to your strSQL, connection and parameters
Dim da As New SqlDataAdapter(command)

'set proper name of table for data set based upon departmentID
If departmentID = 1 Then
Dim ds As New DataSet()
da.Fill(ds, "dtCarriers")
Return ds
End If


'set proper name of table for data set based upon departmentID
If departmentID = 2 Then
Dim ds As New DataSet()
da.Fill(ds, "dtProducts")
Return ds
End If

End Function

View 4 Replies View Related

Problems Passing String Value To Stored Procedure

Aug 2, 2005

Hello, I'm trying to pass a simple string value to a stored procedure and just can't seem to make it work.  I'm baffled since I know how to pass an integer to a stored procedure.  In the example below, I don't get any compile errors or page load errors but my repeater doesn't populate (even though I know for certain the word "hello" is actually in the BlogTxt field in the db.  If I change the stored procedure to say...WHERE BlogTxt LIKE '%hello%'then the results do indeed show up in the repeater.I ultimately would like to pass text from a textbox control or maybe even a querystring to the stored procedure.  Then I'll move on to passing multiple "keywords" to it. :)My relevant code is below.  Thanks in advance for any help.*******************ViewData.ascx.vb file*******************Private strSearch As String
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.LoadTry Dim objBlogController As New BlogController 'for testing purposes  strSearch = "hello" repeaterSearchResults.DataSource = objBlogController.SearchBlog(strSearch) repeaterSearchResults.DataBind()Catch exc As Exception  ProcessModuleLoadException(Me, exc)End TryEnd Sub----------------------------------------
*******************Controller.vb file*******************
Public Function SearchBlog(ByVal strSearch As String) As ArrayList            Return CBO.FillCollection(DataProvider.Instance().SearchBlog(strSearch), GetType(BlogInfo))        End Function----------------------------------------
*******************        DataProvider.vb file*******************
Public MustOverride Function SearchBlog(ByVal strSearch As String) As IDataReader----------------------------------------
*******************SqlDataProvider.vb file*******************
Public Overrides Function SearchBlog(ByVal strSearch As String) As IDataReader            Return CType(SqlHelper.ExecuteReader(ConnectionString, DatabaseOwner & ObjectQualifier & "SearchBlog", strSearch), IDataReader)End Function----------------------------------------
*******************Stored Procedure*******************
CREATE PROCEDURE dbo.SearchBlog @strSearch varchar(8000)AS
SELECT ItemID, PortalID, ModuleID, UserID, BlogTxt, DateAdd, DateModFROM BlogWHERE BlogTxt LIKE '%@strSearch%'GO----------------------------------------

View 3 Replies View Related

Passing Variable To String Compare In Function

Dec 8, 2007

I have created a function with:

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO

ALTER FUNCTION [dbo].[fn_concat_boxes](@item varchar, @week int)
RETURNS VARCHAR(100)
AS
BEGIN

DECLARE @Output varchar(100)

SELECT @Output = COALESCE(@Output + '/', '') +
CAST(quantity AS varchar(5))
FROM flexing_stock_transactions
WHERE item = @item AND week = @week
GROUP BY quantity
ORDER BY quantity

RETURN @Output


END

how can I pass the variable @item correctly for the string comparison

WHERE item = @item AND week = @week

to work correctly please?

WHERE item = '@item' AND week = @week

won't work and

WHERE item = @item AND week = @week

won't work.

View 2 Replies View Related

Passing An IN (a, B, C) List To A Sproc As A String -- Best Method?

Jul 20, 2005

I want to do something like this in a stored proc:------Create Procedure dbo.GetPatients@PatientIdList varchar(200) -- comma separated list of PatientIDsAsSelect *From PatientsWhere PatientId In (@PatientIdList)------I know the above won't work, but of course what I want is if@PatientIdList = '1,2,3' then I want Patient records with PatientIds1, 2, and 3 returned.It looks like the only way to do this is to build the SQL statement asa string within the stored procedure ... which pretty much defeats theusefulness of using precompiled sprocs as I understand it (better offbuilding a dynamic query against a View in that case).Thoughts?Joel Thornton ~ <groups@joelpt.eml.cc>

View 1 Replies View Related

Identifier! [problem In Passing A Lengthy String To An SP]

Sep 5, 2006



exec sp_SearchProductAdvanced "(name LIKE '%a%' Or name LIKE '%b%' Or name LIKE '%c%' Or name LIKE '%d%' Or name LIKE '%e%' Or name LIKE '%f%')and (salesprice between 3 and 10) ",null

after executing i got this error:

The identifier that starts with '(name LIKE '%a%' Or name LIKE '%b%' Or name LIKE '%c%' Or name LIKE '%d%' Or name LIKE '%e%' Or name LIKE '%f%')and (salesprice ' is too long. Maximum length is 128.

how can i solve this problem. so that i can use more values .

my lenght exceeds 128. is there any way to get rid of this.

in my SP i have declared the parameter variable as

@criteria nvarchar(1000)



View 9 Replies View Related

Error Passing Concatenated String To Proc

Nov 8, 2007

Hi,

I have a stored proc which accepts a varchar(255) as a parameter and when I call the proc using a concatenised string I get an error i.e.

-- Proc
CREATE PROCEDURE #proc_param_test
@p_param1 varchar(40) = NULL
, @p_param2 varchar(40) = NULL
AS
BEGIN
SELECT @p_param1, @p_param2
END

EXEC #proc_param_test 'test', 'test 2'
returns
---------------------------------------- ----------------------------------------
test test 2

but EXEC #proc_param_test 'test', 'test 2' + ' - the rest'

gives a Incorrect syntax near '+'. error

The solution must be a real doddle but it's a 'mare to find anywhere.

Cheers,
John

View 4 Replies View Related

Passing A Multivalued String To Stored Procedure

Oct 14, 2007

I have a multivalued parameters populated from a dataset with country codes: US,CA,HK etc... I tried to pass the parameter to the stored procedured but that did not work. I did some research and found out that I won't be able to do that.


Writing Queries that Map to Multivalued Report Parameters

http://msdn2.microsoft.com/en-us/library/ms155917.aspx


You can define a multivalued parameter for any report parameter that you create. However, if you want to pass multiple parameter values back to a query, the following requirements must be satisfied:
The data source must be SQL Server, Oracle, or Analysis Services.
The data source cannot be a stored procedure. Reporting Services does not support passing a multivalued parameter array to a stored procedure.
The query must use an IN statement to specify the parameter.
If I am not able to pass the parameter that way, what is the best way to accomplish my goal?
Thanks,
Elie

View 5 Replies View Related

How Do I Assign A String To A Parameter I'm Passing To A Select Statement?

Oct 30, 2006

Hello, I'm needing to pass a variable length number of values to a select statement so I can populate a result list with items related to all the checkboxlist items that were selected by the user.  for example, the user checks products x, y and z, then hits submit, and then they see a list of all the tests they need to run for each product. I found a UDF that parses a comma delimited string and puts the values into a table.  I learned how to do this here: http://codebetter.com/blogs/darrell.norton/archive/2003/07/01/361.aspx I have a checkboxlist that I'm generating the string from, so the string could look like this: "1,3,4,5,7" etc.I added the function mentioned in the URL above to my database, and if I understand right, I should be able to pass the table it creates into the select statement like so:
WHERE (OrderStatus IN ((select value from dbo.fn_Split(@StatusList,','))) OR @StatusList IS NULL) but now I don't know how to assign the string value to the parameter, say to '@solution_id'.my current select statement which was generated by Visual Studio 2005 looks like this: SELECT [test], [owner], [date] FROM [test_table] WHERE ([solution_ID] = @solution_ID) ...but this only pulls results for the first item checked in the checkboxlist.Does anyone know how this is done?  I'm sure it's simple, but I'm new to ASP .NET so any help would be greatly appreciated.    

View 3 Replies View Related

Passing A String Into The InsertCommand Of SqlDataSource At The @color Character

Apr 27, 2007

Ok, so I'm a JSP guy and thing it should be easy to replace "@color" with t_color after I initialized it to red by         String t_color = "red";and then calling the insert         SqlDataSource1.Insert();here is insert command:             InsertCommand="INSERT INTO [favcolor] ([name], [color]) VALUES (@name, @color)"  I've tried       InsertCommand="INSERT INTO [favcolor] ([name], [color]) VALUES (@name, "+ t_color+")"  Ive tried        InsertCommand="INSERT INTO [favcolor] ([name], [color]) VALUES (@name, "<%$ t_color %>" )"   Is there any easy way to do this? or Can I set it like @color = t_color?  Thanks in advance for ANY help JSP turning ASP (Maybe)Dan 

View 4 Replies View Related

SQL Reporting Services String Parameter Passing To SQL IN Clause

Sep 21, 2004

Is it possible to pass a report parameter that is defined as a string to the following SQL statement that is using an "IN" clause ?

WHERE (ANALYST.User_Bemsid IN (@Report_Parameter_Bemsid))

If I pass a single value (I.E. A) it works okay, but once I try to pass multiple values (I.E. A,B or 'A','B') it returns no data.

Using Crystal reports I can pass multiple values via a report prompt into the SQL "IN" clause and seems that SQL Reporting Services should also have this feature. What do I need to do to get it working ?

Thanks for any help...

View 4 Replies View Related

Passing A Comma Delimited String Of Parameters To A Stored Proc

Jul 30, 2007

Hello,
I have a number of multi-select parameters which I would like to send to a stored procedure within the dataset for use in the stored procedure's IN() statement which in turn is used to filter on or out particular rowsets.

I considered using a hidden string parameter set = " ' " + join(parameter.value, ',') + " ' " so that the hidden parameter would then contain a comma delimiated string of the values selected, which would then be sent on to the stored proc and used in the WHERE clause of one of the queries internal to the stored proc.
But before I start dedicating time to do this I wanted to inquire if anyone here with far more expertise could think of a faster or less system heavy method of creating a single string of comma delimited parameter selections?

Thanks.

View 3 Replies View Related

Passing Around Message Contents As Streams (conversion To/from String &&amp; XmlDoc's).

Oct 2, 2006

More of a general "Streams" question than broker specific, but this is all being done in the context of Broker passing the messages around. The use of Streams & Encoding seems to be my problem and I'm not as familiar with Streams as I am with other areas of the Framework... Any advice would be appreciated.

At this point, I've created my own objects/stored procedures based loosely on the ServiceBrokerInterface class provided in the SQL Server samples. Some of this was done for simplification and as a learning exercise, but also to ensure that all of the SQL operations are being done via Stored Procedures and not inline SQL. This was done to adhere to our existing security policy used on this project.

In this "interface" I've built, I have a [BrokerMessage.cs] class which is meant to have a few additional pieces of functionality beyond what the MS provided version had supplied.

1st... A constructor for accepting either String or XmlDocument as the "content"

2nd... Methods to return either a XmlDocument or a simple String.

Since all of the Broker functionality is defined as using VARBINARY(MAX) in my stored procedures, I don't believe I have any problems at that level. It's simply a binary blob to Broker.

In my constructor for accepting String or XmlDocuments, I attempted to use the following...

public BrokerMessage(string type, XmlDocument contents)

{

m_type = type;

m_contents = new MemoryStream(EncodingProvider.GetBytes(contents.InnerXml));

}

My understanding was that MemoryStream is derived from Stream so I can implicitly cast it. The "EncodingProvider" is a static member set as follows:

public static Encoding EncodingProvider = Encoding.Unicode;

This way I ensure that internal & external code can all be set to use the same encoding and easily changed if necessary. I was hoping to avoid using Unicode since the rest of the application does not require it, but from my understanding all Xml documents in SQL Server are Unicode based, so this should be a better encoding choice for any processing that may potentially occur within SQL Server itself.

In my methods to return the various forms of the "Stream", I have the following code... The ToBytes() method is what is used to pass intot he stored procedure parameter that is defined as VarBinary and expecting a byte array. One area of concern is that the Read method accepts an INT for the length, but the actual Length property is a LONG. I'm sure there's a better way to handle this and I would welcome any advise there.



/// <summary>

/// Used to convert from a Stream back to a simple Byte array.

/// </summary>

/// <returns></returns>

public virtual byte[] ToBytes()

{

byte[] results = new byte[this.Contents.Length];

this.Contents.Read(results, 0, (int)this.Contents.Length);

return results;

}

/// <summary>

/// Used to convert from a Stream back to a simple String.

/// </summary>

/// <returns></returns>

public new string ToString()

{

byte[] buffer = this.ToBytes();

String results = EncodingProvider.GetString(buffer);

return results;

}

/// <summary>

/// Used to convert from a Stream back to a simple XmlDocument.

/// </summary>

/// <returns></returns>

public virtual XmlDocument ToXmlDocument()

{

XmlDocument results = new XmlDocument();

results.InnerText = this.ToString();

return results;

}



View 5 Replies View Related

Passing Multiple String Values Separted By A Comma As One Parameter

Oct 16, 2007



Hello,



I have a stored procedure that accepts one parameter called @SemesterParam. I can pass one string value such as €˜Fall2007€™ but what if I have multiple values separated by a comma such as 'Fall2007','Fall2006','Fall2005'. I still would like to include those multiple values in the @SemesterParam parameter. I would be curious to hear from some more experienced developers how to deal with this since I am sure someone had to that before.



Thanks a lot for any feedback!

View 6 Replies View Related

INCORRECT SYNTAX NEAR STRING FOR ALTER SQL

Oct 20, 2007

HELP
I am trying to create a new column for every file in a folderbut i keep getting an sql exception  - incorrect syntax near ' whatever the value of the file name is'it works if i just type in the value directlymy code look like this
 fsofolder = CreateObject("Scripting.FileSystemObject")
        folder = fsofolder.GetFolder("the path to the Files")
        files = folder.Files
        For Each objfile In files
            sname = objfile.Name
                  
            cmd3.CommandText = "ALTER TABLE NEW ADD " & "' " & sname & " ' " & " nvarchar(MAX)"

            DatabaseConnection.Open()

            Try

                cmd3.Connection = DatabaseConnection
                cmd3.ExecuteNonQuery()
            Catch ex As SqlException
                MsgBox(ex.Message)
            End Try

            DatabaseConnection.Close()

View 10 Replies View Related

AS2005 Format String Syntax

May 7, 2008

I'm new here so I'm not sure if this is the correct spot to post this question but here goes.

In the cube design view under the Calculations tab I have several calculated members that I have created. Each of these are dollar amount fields for which I have defined a Format String property as follows:

Format String: "$#,##0;($#,##0);;N/A"

This format correctly handles my positive value, Negative value and my NULL value the way I want. However I need to deloy this cube on one of my UK severs and I don't want the $ but instead I would like the pound sign without having to recreate this entire project to do so. I have tried the following syntax but it is incorrect.

Format String "Currency;;;N/A"

Can someone help me with the correct way to code the property so that I can get my currecy symbol based on the regional setting as well as handle my NULL values.

Thanks

View 1 Replies View Related

Passing GUID Into Dtexec, Invalid Cast To A String Variable. Solution??

Oct 4, 2006

I am getting an invalid cast specification when I call dtexec and try to /SET a user variable within the package that is defined as a string data type. Is there any solution to this? I have tried passing the GUID with {} w/o {} w/ '' w/ "" etc.. many variations... and still get an invalid cast specification. Is there a data type that I need to set the User variable to besides String? The User Variable is used to Select records from a SQL data source where the GUID is stored. I do not have an option of GUID data type for a User Variable.

Thanks for any help! Aaron B.



View 3 Replies View Related

User Vars Of Type String Initialized To Nulls Not Passing Correctly To Sp

Feb 24, 2008

i defined 3 pkg scope user variables of type string in the ssis variables window, typed null as their value, and tried passing them (thru exec sql task) to an sp who expects 3 varchar(23) params.

The sp is blowing up because their values arent null.

The sql task command reads exec sp_name ?,?,?. In the sql task editor's param mapping window, I have each param listed with direction "input", data type varchar and the individual sp params in the parameter name column. I think the plumbing is set up correctly because I'm fine when I send the System Variable StartTime as a 4th param to the sp with data type DATE on the ssis end and datetime on the sp end.

Does anyone know if ssis string and engine varchar are incompatible or perhaps if null in the variables window doesnt initialize variables?

View 1 Replies View Related

Transact SQL :: Passing Multiple String Param Values To Stored Proc

Jul 21, 2015

CREATE TABLE Test
(
EDate Datetime,
Code varchar(255),
Cdate int,
Price int
);

[Code] ....

Now I have to pass multiple param values to it. I was trying this but didnt get any success

exec
[SP_test]'LOC','LOP'

View 10 Replies View Related

Integration Services :: Passing Connection String Dynamically To SSIS Package

Jul 12, 2012

I have create packages which loads the data from flat file to sql server table, now I want to make my destination table connection dynamic what is format of connection string. I also need to pass user name and password for sql server dynamically in this case, what is the format for the connection string.

Also  in package i used ADO.net  as source for  *.mdb files how i can set the commection to .mdb files dynamically which is used as source in my package.

View 8 Replies View Related

String Or Binary Data Would Be Truncated // Is There A Maximum Length For Passing An Nvarchar Max To A Function?

Mar 18, 2008

I'm running into this error message when passing in a few records in particular to a function, the only difference I could find is that these recods have about 60k characters on the field that I'm passing to a function.

is there a max lenght for passing to a function?

select function ( field) as results

It's been working fine until today and all of the related fields are declared as nvarchar(max)

Thank you.

View 5 Replies View Related

Syntax Error Converting Datetime From Character String

Aug 6, 2004

Here's the deal. I'm a newbie trying to update a date (@Effective) in sql server. I've been trying all sorts of things, but nothing seems to work. Here's my current code:

Sub btnUpdate_Click(sender As Object, e As EventArgs)
Dim sqlStmt As String
Dim conString As String
Dim cn As SqlConnection
Dim cmd As SqlCommand
Dim sqldatenull As SqlDateTime
Try
sqlStmt = "UPDATE [Submission] SET [Effective]=Convert(DateTime, '@Effective', 101), "& _
"[Status]=@Status WHERE ([Submission].[Submission]=@Submission)"
conString = "server='(local)'; user id='sa'; password='password'; database='database'"
cn = New SqlConnection(conString)
cmd = New SqlCommand(sqlStmt, cn)

cmd.Parameters.Add(New SqlParameter("@Submission", SqlDbType.Int, 4))
cmd.Parameters.Add(New SqlParameter("@Effective", SqlDbType.VarChar, 10))
cmd.Parameters.Add(New SqlParameter("@Status", SqlDbType.VarChar, 8))

sqldatenull = SqlDateTime.Null

If (txtEffective.Text = "") Then
cmd.Parameters("@Effective").Value = sqldatenull
Else
cmd.Parameters("@Effective").Value = txtEffective.Text
End If
cmd.Parameters("@Status").Value = dropStatus.SelectedItem.Text
cmd.Parameters("@Submission").Value = LabelSubmission.Text

cn.Open()
cmd.ExecuteNonQuery()
cn.Close()
Response.Redirect("main.aspx")

Catch ex As Exception
lblError.Text = ex.Message
Finally
cn.Close()
End Try
End Sub


My db is setup as follows:

Submissionint4
Insuredvarchar30
Statevarchar2
Effective datetime 8
Underwritervarchar9
Statusvarchar8
Cleareddatetime 9


I'm losing my hair by the fist full... Somebody please stop the insanity!

View 2 Replies View Related

Syntax Error Converting Datetime From Character String - HELP PLEASE!

Apr 20, 2005

Somewhere, either in the
aspx.vb code, or the stored procedure that's being called, it doesn't
like my code since I am getting the dreaded "syntax error converting
datetime from character string" error.  I've been battling this
for two days - can someone spot what is wrong here?

The dtWdate variable is coming from a calendar control on my aspx page.
Please help - I've tried every conceivable way I can think to do this without success.
Lynnette

Here's the code:
    Private Sub GetFLSAEmpInfoRecs()
        'uses the AppSettings table to generate WHERE clause from the filter values

        Dim dtWdate As DateTime = Calendar1.SelectedDate
        Dim wValue As String = Session("svFilterValue")

        Dim cnn As New SqlConnection(constants.SQLConStrFLSA)
        Dim cmd As New SqlCommand("usp_AddFLSA", cnn)
        cmd.CommandType = CommandType.StoredProcedure
        cnn.Open()

        cmd.Parameters.Add(New
SqlParameter("@dtWDate", SqlDbType.DateTime)).Value =
Convert.ToDateTime(dtWdate)
        cmd.Parameters.Add(New
SqlParameter("@whereString", SqlDbType.VarChar, 500)).Value = wValue
      
        cmd.ExecuteNonQuery()
        cnn.Close()

    End Sub

And here is the stored procedure:

ALTER PROC usp_AddFLSA
  @dtWdate datetime,
  @whereString as varchar(255)
AS
DECLARE @strSQL as varchar(2000)

SET @strSQL =
'
INSERT INTO FLSAEmpInfo
( Emp_Number,
  PT_ID,
  Emp_Division,
  Emp_DeptInfo,
  Emp_Supervisor,
  Emp_Location,
  Emp_Union,
  Emp_SG,
  Emp_Shift,
  WrkDate
)
SELECT
  hcsoSharedTables.dbo.Employee2.Emp_Number,
  hcsoSharedTables.dbo.Employee2.[ID],
  hcsoSharedTables.dbo.Employee2.Division,
 
dbo.udf_getDeptInfo(hcsoSharedTables.dbo.employee2.Department,hcsosharedtables.dbo.employee2.Dept_Mgr,hcsosharedtables.dbo.employee2.job_dept_code),
  hcsoSharedTables.dbo.Employee2.Job_Supervisor,
  hcsoSharedTables.dbo.Employee2.Loc_Name,
  hcsoSharedTables.dbo.Employee2.[Union],
  hcsoSharedTables.dbo.Employee2.Sched_Group,
  hcsoSharedTables.dbo.Employee2.Shift,' +
  @dtWdate + ' ' + 'FROM hcsoSharedTables.dbo.Employee2' + @whereString

EXEC(@strSQL)

View 4 Replies View Related







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