How To Cast Empty String

I want to replace a column value with a null if the string is empty. I would have thought this simple expression would do it:

RTRIM([FromContractSymbol]) == "" ? NULL(DT_STR, 0, 1252) : (DT_STR, 6, 1252)FromContractSymbol

Yet, I get the following error:

For operands of the conditional operator, the data type DT_STR is supported only for input columns and cast operators. The expression "...see above..." has a DT_STR operand that is not an input column or the result of a cast, and cannot be used with the conditional operation.

The expression works if I replace the NULL(DT_STR, 0, 1252) with say "A" and the expression works on other non-string columns. (As in "NULL(DT_I1) : (DT_I1)100")

View Replies


Cast String To Int

Hi ,

I have a problem with casting a string number to int.
for exmaple i have the number '0110' (string) and i would like it to be 110. or '0001' to be 1.
i tried to do:
cast(MyNUM as int) .
but i get "Syntax error converting the nvarchar value 'O322' to a column of data type int."

is anyone have any idea how to solve it ?


View Replies View Related

Cast From String To Date

I created an SSIS package that pulls in legacy data from a DB2 AS400. There is an In Date field that is stored on the AS400 as OdbcType.Date or DATE. However, when I use SSIS to pull in the data, SQL wants it to be a string so I gave up and let SQL have it's way.

Now in my SELECT statement, I have this:

WHERE (TLMST.INDT >= @startdate) AND (TLMST.INDT <= @enddate)

Because I see the dates stored in TLMST are yyyy-mm-dd format, this is not working. It is not pulling any records. I tried to use the CAST statement but I keep getting errors about casting from a string to a date and data overflow errors.

Should I go back and re-do the SSIS or is there a way to pull the records for this? Thanks for the information

View Replies View Related

Conditional Statement With A Cast From String To Date

My source file is showing column 10 as string. My destination table is datetime. I am using the derived transformation with a conditional statement. How do I convert the value from string to date. Everywhere I try the (DT_DATE) I get an error.

[Column 10] == "01/01/0001" ? " 01/01/1801" : [Column 10] <= "12/31/1801" ? "12/31/1801" : [Column 10]

View Replies View Related

Cast From String 'OPEN' To Type 'Double' Is Not Valid.

Hi.. Please help me resolve this error "Cast from string 'OPEN' to type 'Double' is not valid.". Error here If CallStatus = 10 Then ....Code:Public Sub UpdateCallStatus()        Dim CALLID, RequestorID, CommentsFromITD, MessageFromITD, MessageToITD, CallStatus, strSQL As String        CALLID = Request.QueryString("CallID")        RequestorID = Session("USER_ID")        CommentsFromITD = lblcomments.Text        MessageFromITD = lblmessage.Text        MessageToITD = txt_desc.Text        CallStatus = Trim(Request.Form(ddl_callstatus.UniqueID))
        Dim ObjCmd As SqlCommand        Dim ObjDR As SqlDataReader
        Try            If CallStatus = 10 Then                strSQL = "UPDATE CALLS  SET STATUS_ID=" & CallStatus & " WHERE CALL_ID=  " & CALLID & ""                ObjCmd = New SqlCommand(strSQL, ObjConn)                ObjConn.Open()                ObjDR = ObjCmd.ExecuteScalar()                gbVariables.insertuserevents(CALLID, RequestorID, "Call Closed")                Response.Redirect("UserCallClosed.aspx")                ObjConn.Close()            Else                strSQL = "UPDATE CALLS  SET STATUS_ID=" & CallStatus & " WHERE CALL_ID=  " & CALLID & ""                ObjCmd = New SqlCommand(strSQL, ObjConn)                ObjConn.Open()                ObjDR = ObjCmd.ExecuteScalar()                ObjConn.Close()
                strSQL = "SELECT STATUS_LABEL  FROM STATUS WHERE STATUS_ID = " & CallStatus & ""                ObjCmd = New SqlCommand(strSQL, ObjConn)                ObjConn.Open()                ObjDR = ObjCmd.ExecuteScalar()                ObjConn.Close()
                gbVariables.insertuserevents(CALLID, RequestorID, CallStatus)                CallStatus = ""            End If        Catch ex As Exception            lblmsg.Text = ex.Message.ToString        End Try    End SubThanks...

View Replies View Related

Type Cast Error Converting From Integer To String

I am attempting to convert an integer value to a string using the Derived Column transformation with the following expression on the field:

prod_id is an integer. I was able to do this before however, in the past couple of days, this has failed with the following error:
"An error occurred while attempting to perform a type cast."

To my knowledge, I have not changed anything about this particular data flow within the past couple of days. I have verified that the value is coming in as an integer.

Any help would be greatly appreciated.

View Replies View Related

Unable To Cast Object Of Type 'System.String' Error Help

Unable to cast object of type 'System.String' to type 'System.Web.UI.DataSourceSelectArguments'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.InvalidCastException: Unable to cast object of type 'System.String' to type 'System.Web.UI.DataSourceSelectArguments'. 
Hi, In my pageload i have data retriving from a page and i want it to load it in the GridView. i have GridView and SqlDataSource but when the page loads i am getting the above error. i am not sure what im doing wrong here. i tried different ways. but no luck Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Thenfp = CType(Context.Handler, Member)
'lblEmail.Text = fp.EMM.ToString
'this labelbox for Email address is under the Name'lblEmail.Text = fp.EmailAddress.ToString
 Dim conn As SqlConnection = New SqlConnection(ConfigurationManager.ConnectionStrings("imacstestConnectionString").ConnectionString)
Dim cmd As SqlCommand = New SqlCommand("SELECT , [fname], [mname], [lname], [address], [city], [state], [zip], [phone] FROM [t_CustomerAcct] WHERE = @email", conn)cmd.Parameters.AddWithValue("@email", fp.EMM.ToString)
End If
End Sub

View Replies View Related

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

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 Replies View Related

Empty String To Null

create view v_GuestOrder
Select T1.id_Guest,T2.OrderName
from Guest T1
left join Order T2 T2.id_order = T1.Id_order

select * from v_GuestOrder
Id_Guest OrderName
-------- -----
1 spoon
2 phone
4 tv

I need something similar to

case orderName
when '' then Null -- Sql server gives error in thsi case
end as orderName
from v_GuestOrder

So I need to assign NULL to OrderName is query return empty string,
it will be treated by Crystal reports as Null

Please help , thanks

View Replies View Related

Bcp Out Empty String Into Csv Files

I have a SQL Server table with nvarchar type column which has not null constraint. I am inserting empty string ("") from Java to the table column. When I export this table into .csv file using bcp tool, empty string gets written as NUL character. Is there any way I can bcp out empty string as empty string itself instead of NUL to the file?

View Replies View Related

Constraint For An Empty String

How do I prevent a column having empty strings entered into it. I want to allow
nulls but not allow empty strings.


View Replies View Related

Insert Empty String Or Null To Sql Db

Trying to insert null value into sql table, but not working, if I use:
 if (strMyText.Length == 0)        command.Parameters.Add("@Text", DBNull.Value); // or using:("@Text", null), or using:("@Text", DBNull) else         command.Parameters.AddWithValue("@Text", strMyText); 
When I go back to table, I see the value is: 'NULL', has single quotation mark, suppose to be: NULL
Where is the problem?
Thanks a lot.

View Replies View Related

Checking If String Is NULL Or EMPTY In SQL

I need to check in my Stored procedure if the information passed is null or empty so I can decided to insert the new value or keep the old. How do I accomplish this please in T-SQL. Thanks in advance.

View Replies View Related

Null Or Empty String Use More Space?

Hi all,   I have some columns in my database which allows null.  I want to know if leaving the field to be NULL or storing an empty string into the field, which will take up more space?? if the field type is varchar(100)

View Replies View Related

HELP : Empty String To Null Conversion By SQL

Hi folks,

I've have about 100 tables, for some reasons, column values that are originally NULL was inserted as emtpy string. So, I am wondering if I can write JUST ONE SQL (hopefully don't have to specify the field names in the SQL as well) for each table so that all the empty strings will be converted back to NULL.


View Replies View Related

HELP : Empty String To Null Conversion By SQL

Hi folks,

I've have about 100 tables, for some reasons, column values that are originally NULL was inserted as emtpy string. So, I am wondering if I can write JUST ONE SQL (hopefully don't have to specify the field names in the SQL as well) for each table so that all the empty strings will be converted back to NULL.


View Replies View Related

How To Use /Set Option To Set A Variable To Empty String


I developed an SSIS package and I'm using the dtexec utility to run it. The package has a variable RunDate (datetime) and i want to set this value to "" (empty string) when i try to run this package using the dtexec.

Currently I'm getting an error Argument option not valid.
Thanks in advance

View Replies View Related

Referential Integrity With Empty String And ZERO

How could I define referential integrity using FK constraint which allow me to have empty string/ZERO number instead of NULL value ?

Thank you

View Replies View Related

How To Specify An Empty String As A Default Column Value?

In the Column Properties window's 'Default Value or Binding' property, how do you specify an empty string?


View Replies View Related

Default Empty String Value For Varchar Columns

Hi guys,
Is there a way to declare a default value of empty string '' for a varchar table column?

View Replies View Related

NULL Values Vs Empty String Vs Space

How do I define a field to have the default value = ''. Not NULL but not a space either in SQL Server 2005?

View Replies View Related

Bcp Is Inserting Blank Space For Empty String

I'm doing a bcp out of a table to a file. Some of the fields in arecord may have an empty string.When I bcp out to the file and examine it, the fields that have anempty string in the database now show up in the file as having oneblank character.Why is bcp doing this? I don't want the blank character in my output.Thanks,Eric

View Replies View Related

Select Returning Nbsp Instead Of An Empty String

I am using a SQLDataSource with the following Select query. If the "spouse" values are not in the database, I get the HTML non-breaking-space character back, rather than an empty string.

SelectCommand="select applicant_id, (applicant_last_name + ', ' + applicant_first_name) as applicant_name, CONVERT(varchar(10), applicant_dob, 101) as applicant_dob, applicant_ssn, (spouse_last + ', ' + spouse_first) as spouse_name, CONVERT(varchar(10), spouse_dob, 101) as spouse_dob, spouse_ssn from applicant where applicant_last_name like '%'+@last_name+'%' order by applicant_last_name"

Here is the relevant code-behind:

TextBox tb = (TextBox)formView.FindControl("SpouseName");

tb.Text = e.Item.Cells[4].Text;

DatePicker dp = (DatePicker)formView.FindControl("SpouseDateOfBirth");

if (e.Item.Cells[5].Text.Length > 0)


try // this is a try/catch because nbsp is not parsed as a date


dp.DateValue = DateTime.Parse(e.Item.Cells[5].Text);




dp.txtDate.Text = "";



tb = (TextBox)formView.FindControl("SpouseSocialSecurityNumber");

tb.Text = e.Item.Cells.Text;



View Replies View Related

Why CodeBase Property Of CurrentAssembly In CLR SP Is Empty String?

Where is SQL storing and caching the assemblies used by CLR SP?

I want to read a mapped configuration file for that assembly but it seems that assemblies are not read form their initial location.

Is there a way to use configuration files for the assemblies used by CLR SPs? (I don't want to use a static string to point to a file on the disk)

View Replies View Related

Empty String Problem In Joined Data

I have a problem where I need to include data from a table where one of the joined columns can contain empty strings. The emptry string column and its related columns need to be included in the results of the query.

The Join looks like this:

SalesData.dbo.tbl_CYProcessedSales ps
INNER JOIN SalesData.dbo.vw_Product_CYProcessedSalesXref xr
ON ps.Prod = xr.Prod
AND ps.Acct = xr.AcctCode
INNER JOIN TxnRptg.dbo.vw_NetNewRevenueUnion nn
ON xr.BillingType = nn.BillingType
AND xr.ProdGroup = nn.Product
AND xr.AcctCode = nn.AcctCode

The problem occurs on the xr.BillingType = nn.BillingType portion of the join. the nn.BillingType can contain empty strings. I've tried a LEFT join to vw_NetNewRevenueUnion, but this has not worked.

In vw_NetNewRevenueUnion, BillingType becomes an empty string within a CASE statement if BillingType is NULL. I've thought about using something like 'All' in the ELSE condition, and doing the same in the vw_Product_CYProcessedSales view just so I don't have to deal with an empty string.

If I were not to do that, is there some way I can handle the empty string issue within the join so that empty string records will be included in the query results?

Thank you for your help!


View Replies View Related

Detect And Convert An Empty String (from Textbox) To Null?

 Hi all,I have this code that I use for my Search function:SELECT DISTINCT [MUSIC_TITLE], [MUSIC_ORIGINAL_SINGER], [MUSIC_PERFORMER]FROM t_musicWHERE (@MUSIC_TITLE IS NULL OR [MUSIC_TITLE] LIKE '%' + @MUSIC_TITLE + '%') AND (@MUSIC_ARTIST IS NULL OR ([MUSIC_ORIGINAL_SINGER] LIKE '%' + @MUSIC_ARTIST + '%' OR [MUSIC_PERFORMER] LIKE '%' + @MUSIC_ARTIST + '%')) But right now if I don't enter anything in one of the textbox (2 have two, either of them can be left empty), the above Sql statement doesn't return anything since ADO.NET can't tell an empty textbox and treat it at null... So anyone please help me how to detect an empty textbox and set that to null for the above SQL statement to work. (It work in SQL Manager Studio, when I set one of the parameter = null.) I'm very new to ASP.NET stuffs, so if someone can help me to convert that function to code-behind and help me to call it from the .aspx, that would be even better as I don't want to put the code in my .aspx page... But I'm not quite there yet. Thank you all,Kenny.  

View Replies View Related

Converting Empty String To Null When Inserting/updating

    I am using the following query to calculate date differences:select ..........DATEDIFF(d,  recruitment_advertising.advertising_date, career_details.RTS_Email AS Datetime) AS Ad_to_RTS_days FROM .....I have stored all my dates as NVARCHAR because of the issues with localization.If the value is an empty String my output is eg: -38700. which is way off and incorrect. Some of the values in my table are NULL and they produce the correct result.Is there a T-SQL statement to replace empy Strings with the NULL value in my tables.I'd like to use it as a trigger when inserting or updating to convert empty strings to NULLbefore the values are inserted.Thanks guys.

View Replies View Related

Oracle Empty String == NULL Behavior In SQLServer 2k5?

I'd like to have Oracle's empty string behavior in SQLServer 2k5. Oracle treats an empty string as NULL's.

In PL/SQL can do:
... and it'd return rows containing NULL's as well as empty strings.

Can this be done? I couldn't find a setting for it.



View Replies View Related

Lookup Transform Still Cannot Find Empty String Matches

Has anyone find solution for this problem.
i also checked and

Suppose have a Dimension table

ColorKeyPK(smallint) ColorAlternateKey(nvarchar(30))
-1 UnknownMember
2 Blue
3 Red
4 Black

Color with the ID 1 is empty string

OrderID Date Color Quantity

OrderID = 1 Color = 'Black' Quantity = 10
OrderID = 2 Color = 'Red' Quantity = 20
OrderID = 3 Color = '' Quantity = 10
OrderID = 4 Color = 'Blue' Quantity = 5
OrderID = 5 Color = Black Quantity = 10

When i use the Lookup transform it cannot find the ColorKeyPK

The result of the Lookup transform is.
OrderID = 1 Color='Black' ColorKey=4
OrderID = 2 Color='Black' ColorKey=3
OrderID = 3 Color='Black' ColorKey=NULL ----> This is the problem Lookup cannot find empty string. It should be 1.
OrderID = 4 Color='Black' ColorKey=2
OrderID = 5 Color='Black' ColorKey=4

Thanks from now.

View Replies View Related

Empty String Equals To Blank: How To Change This Behaviour?

This seems to be a rather old problem ( but I couldn't find an answer yet.

The problem is: I have two tables t1 and t2 where t1 is a staging area of t2.
t1: (id int not null, phone varchar(30))
t2: (id int not null, phone varchar(30))

Data in t1: (1, '') <- empty string
Data in t2: (1, ' ') <- a blank

Comparing with results in equality which in my opinion isn't correct.

The question ist: How can I change the behaviour of SQL-Server to result in inequality so that the change in my staging table is detected correctly?

Thanks in advance

View Replies View Related

Why Search On Empty String Returns Results With A Space?

In sql server 2000 - our QA pointed out that his testing for empty strings returned 200 + rows but that when he clicked in the field there were obviously a space there. This issue came up because of the script I created to replace and earlier one that queried on empty strings instead of datalength and the earlier script always reported that it had updated x number of rows regardless of how many times it was run on the same database.

QA query based on the earlier script:
Select * from StringTable
WHERE (LongString = '' OR LongString IS NULL)

My script:
The fields are nvarchars in the newer database but older version of the database had varchars. I had created a script to replace empty strings as follows:

-- if LongString column is varchar - run varchar update else nvarchar update
If exists (Select * from sysobjects o
inner join syscolumns c on =
where = 'LongString' and = 'StringTable' and c.xtype = 167) begin

-- update varchar LongString
UPDATE StringTable
SET LongString = char(32)
-- Select * from StringTable
WHERE ((DATALENGTH(LongString ) < 1) OR LongString IS NULL)

Else Begin

-- update nvarchar LongString
UPDATE StringTable
SET LongString = char(32)
-- Select * from StringTable
WHERE ((DATALENGTH(LongString ) < 2) OR LongString IS NULL)


If exists (Select * from sysobjects o
inner join syscolumns c on =
where = 'ShortString' and = 'StringTable' and c.xtype = 167) begin

UPDATE StringTable
SET ShortString= char(32)
-- Select * from StringTable
WHERE ((DATALENGTH(ShortString) < 1) OR ShortString IS NULL)

Else Begin

-- update nvarchar ShortString
UPDATE StringTable
SET ShortString= char(32)
-- Select * from StringTable
WHERE ((DATALENGTH(ShortString) < 2) OR ShortString IS NULL)


My method for checking for datalength appears to work correctly why doesn't the QA script? I thought it might have to do with the nvarchar used in the table but I changed the column to a varchar and still has the same issue.


View Replies View Related

Copyrights 2005-15, All rights reserved