NULL Values In UNPIVOT Output Possible?

Feb 26, 2008

Hello everyone!

Maybe someone of you folks already stumbled upon this one and can help.


I'm using an Unpivot transform in a dataflow.
I want to unpivot various columns that are all of type dt_str(50).
Some of those (input) columns may contain NULL values in some rows, like this:





col1
col2
col3
col4

BusinessKey
val1
NULL
val3
val4


As I run this package, I'd expect the Unpivot's output looking like this:




BusinessKey
col1
val1

BusinessKey
col2
NULL

BusinessKey
col3
val3

BusinessKey
col4
val4

But Unpivot won't output a Key/Value pair if an input value is NULL.
So in fact the output looks like this (col2 is missing):




BusinessKey
col1
val1

BusinessKey
col3
val3

BusinessKey
col4
val4


The BOL documentation doesn't tell anything about Unpivot behaviour if input values are NULL (or at least I couldn't find it).


Now, is this a known problem?
If so, is there a fix or workaround so that I can tell Unpivot to output NULL values?


Thanks for your help!

View 5 Replies


ADVERTISEMENT

Unpivot Transformation Null Values

Jan 23, 2006

Hi, I am trying to use the Unpivot Transformation, and I have the following mapped out, following the example from the SQL Server 2005 BOL Unpivot Transformation:










Input





Destination Column
Subject
ValueNumeric
ValueString
ValueNumeric

Pivot Key Value

RACE
OTHRRACE
GENDER

Column Name
Subject
RACE
OTHRRACE
GENDER

Data Records
99999
1
NULL
1


88888
NULL
Hispanic
2


77777
2
NULL
2







Desired Output





Pivot Key
FALSE
TRUE



Col Name
Subject
Question
ValueNumeric
ValueString

Data Records
99999
RACE
1
NULL


99999
OTHRRACE
NULL
NULL


99999
GENDER
1
NULL


88888
RACE
NULL
NULL


88888
GENDER
2
NULL


88888
OTHRRACE
NULL
Hispanic


77777
RACE
2
NULL


77777
GENDER
2
NULL


77777
OTHRRACE
NULL
NULL

This doesn't work, however, as I have multiple data types. So unless someone knows a better way, I had to split it into two Unpivot Transformations, which I later Sort and Merge together. The two Unpivot Transformations look like this:









Input




Destination Column
Subject
ValueNumeric
ValueNumeric

Pivot Key Value

RACE
GENDER

Column Name
Subject
RACE
GENDER

Data Records
99999
1
1


88888
NULL
2


77777
2
2






Output




Pivot Key
FALSE
TRUE


Col Name
Subject
Question
ValueNumeric

Data Records
99999
RACE
1


99999
GENDER
1


88888
RACE
NULL


88888
GENDER
2


77777
RACE
2


77777
GENDER
2









Input




Destination Column
Subject
ValueString


Pivot Key Value

OTHRRACE


Column Name
Subject
OTHRRACE


Data Records
99999
NULL



88888
Hispanic



77777
NULL







Output




Pivot Key
FALSE
TRUE


Col Name
Subject
Question
ValueString

Data Records
99999
RACE
NULL


99999
OTHRRACE
NULL


99999
GENDER
NULL


88888
RACE
NULL


88888
GENDER
NULL


88888
OTHRRACE
Hispanic


77777
RACE
NULL


77777
GENDER
NULL


77777
OTHRRACE
NULL

The first Unpivot works great, because the data is mandatory. However, the second is full of NULLs so the actual output from the second Unpivot, prior to the merge looks like this:









Actual Output



Subject
Question
ValueString

99999



88888
OTHRRACE
Hispanic

77777



But I expected (and need) this:









Desired Output



Subject
Question
ValueString

99999
OTHRRACE
NULL

88888
OTHRRACE
Hispanic

77777
OTHRRACE
NULL

I hope someone can give me some advice on this!

Regards,

Richard Hein

View 3 Replies View Related

NULL Values Should Be Displayed As Zero In Output

Jan 20, 2015

I have table

CREATE TABLE [dbo].[tblreg]
(
[RN] [nvarchar](50) NOT NULL,
[SC] [nvarchar](6) NULL,
[DC] [nvarchar](12) NULL,

[code]....

So when i write a select query i want the NULL Values should be displayed as zero in the output.

View 1 Replies View Related

Unpivot Output Comarison

Mar 11, 2008

Hi,

I have a 2 outputs from 2 individual Unpivot transformation, now i want to compare the resultant of these two and find the odd / unmatched rows, could anyone please tell me how to achieve this?

View 3 Replies View Related

Compressing Multiple Rows With Null Values To One Row With Out Null Values After A Pivot Transform

Jan 25, 2008

I have a pivot transform that pivots a batch type. After the pivot, each batch type has its own row with null values for the other batch types that were pivoted. I want to group two fields and max() the remaining batch types so that the multiple rows are displayed on one row. I tried using the aggregate transform, but since the batch type field is a string, the max() function fails in the package. Is there another transform or can I use the aggragate transform another way so that the max() will work on a string?

-- Ryan

View 7 Replies View Related

SQL Server 2012 :: Duplicate Values In UNPIVOT

Feb 18, 2015

I have a set of data in which i have a product number going through 6 stages and each stage has a date. Since the each stages are in columns, I have created a unpivot query to transpose the columns into rows.

The actual result data needs to be in format of

ProductNumber Event_NameEvent_Date Event_Days
101 Stage 1 2/13/2014 1
101 Stage 2 2/13/2014 0
101 Stage 3 2/18/2014 5
101 Stage 4 2/23/2014 5

However the result data i am getting is like

ProductNumber Event_NameEvent_Date Event_Days
101 Stage 1 2/13/2014 1
101 Stage 1 2/13/2014 0
101 Stage 1 2/18/2014 5
101 Stage 1 2/23/2014 5
101 Stage 2 2/13/2014 1
101 Stage 2 2/13/2014 0
101 Stage 2 2/18/2014 5
101 Stage 2 2/23/2014 5

The unpivot query is working fine however I am getting duplicate values in the result. For each productnumber there must be only 6 results however i am getting 24 rows for each product number due to duplication.

I have attached the code and the source data for reference

Code:
SELECT distinct ProductNumber ,
Event_Name ,
Event_Date ,
Event_Days
FROM(
SELECT ProductNumber ,

[Code] .....

View 2 Replies View Related

Can You Unpivot On Multiple Keys With The Unpivot Transform

Oct 17, 2006

Hi all,

I have more than 1 set of columns I'm trying to normalize, can an unpivot transform handle 2 unpivots around DIFFERENT keys in the same transform?

If not, would the suggestion be unpivot into temp tables for whatever needs normalizing, than run an update query to generate the row that is desired?

Thanks in advance.


Mark

View 2 Replies View Related

NULL Values Returned When Reading Values From A Text File Using Data Reader.

Feb 23, 2007

I have a DTSX package which reads values from a fixed-length text file using a data reader and writes some of the column values from the file to an Oracle table. We have used this DTSX several times without incident but recently the process started inserting NULL values for some of the columns when there was a valid value in the source file. If we extract some of the rows from the source file into a smaller file (i.e 10 rows which incorrectly returned NULLs) and run them through the same package they write the correct values to the table, but running the complete file again results in the NULL values error. As well, if we rerun the same file multiple times the incidence of NULL values varies slightly and does not always seem to impact the same rows. I tried outputting data to a log file to see if I can determine what happens and no error messages are returned but it seems to be the case that the NULL values occur after pulling in the data via a Data Reader. Has anyone seen anything like this before or does anyone have a suggestion on how to try and get some additional debugging information around this error?

View 12 Replies View Related

Integration Services :: SSIS Reads Nvarchar Values As Null When Excel Column Includes Decimal And String Values

Dec 9, 2013

I have SQL Server 2012 SSIS. I have Excel source and OLE DB Destination.I have problem with importing CustomerSales column.CustomerSales values like 1000.00,2000.10,3000.30,NotAvailable.So I have decimal values and nvarchar mixed in on Excel column. This is requirement for solution.However SSIS reads only numeric values correctly and nvarchar values are set as Null. Why?

CREATE TABLE [dbo].[Import_CustomerSales](
 [CustomerId] [nvarchar](50) NULL,
 [CustomeName] [nvarchar](50) NULL,
 [CustomerSales] [nvarchar](50) NULL
) ON [PRIMARY]

View 5 Replies View Related

Null Values For Datetime Values Converted To '0001-01-01'

Mar 29, 2006

Hi

can somebody explain me how I can assign a NULL value to a datetime type field in the script transformation editor in a data flow task.
In the script hereunder, Row.Datum1_IsNull is true, but still Row.OutputDatum1 will be assigned a value '0001-01-01' which generates an error (not a valid datetime). All alternatives known to me (CDate("") or Convert.ToDateTime("") or Convert.ToDateTime(System.DBNull.Value)) were not successful.
Leaving out the ELSE clause generates following error: Error: Year, Month, and Day parameters describe an un-representable DateTime.




If Not Row.Datum1_IsNull Then

Row.OutputDatum1 = Row.Datum1

Else

Row.OutputDatum1 = CDate(System.Convert.DBNull)

End If



Any help welcome.

View 1 Replies View Related

Use Order By But Want NULL Values As High Values

Nov 9, 2000

Hi,

My query "select blah, blah, rank from tablewithscores" will return results that can legitimately hold nulls in the rank column. I want to order on the rank column, but those nulls should appear at the bottom of the list

e.g.

Rank Blah Blah
1 - -
2 - -
3 - -
NULL - -
NULL - -

At present the NULLs are at the top of the list, but I do not want my ranking in descending order. Any suggestions?

Thanks
Dan

View 1 Replies View Related

Why Output Is Null?

May 16, 2008

my table is tbl_autoException

iLocationNum sClockPointNum iSOID


1111 00 001
1111 01 001
1111 02 001



i want to have an output like "00,01,02" in a single field for my report textbox,

the following is function for this but output is NULL????


CREATE function J2 ()

returns varchar(8000)

begin

declare @retValue as varchar(8000)

select @retValue = coalesce(@retValue + ',', '') + tbl_AutoExceptions.sclockPointNum

from (select top 100 tbl_AutoExceptions.sclockPointNum

from tbl_AutoExceptions

) tbl_AutoExceptions

return rtrim(ltrim(@retValue))

end

View 4 Replies View Related

Integration Services :: SSIS Package - Replacing Null Values In One Column With Values From Another Column

Sep 3, 2015

I have an SSIS package that imports data from an Excel file, replaces any value in Excel that reads "NULL" to "", then writes the data to a couple of databases.

What I have discovered today, is I have two columns of dates, an admit date and discharge date column, and what I need to do is anywhere I have a null value in the discharge date column, I have to replace it with the value in the admit date column. 

I have searched around online and tried a few things using the Replace funtion in Derived columns but no dice so far. 

View 3 Replies View Related

Problem With Output Parameters That Are Varchar And Null

May 30, 2006

I am using version 9.00.2047.00 SP1 of Visual Studio 2005.

Using ADO.NET, I have been unable to get the Execute SQL task to successfully return the value of an output parameter defined as varchar or nvarchar when the value is null. No other data types seem to have this problem, including the sql_variant data type.

Here is the stored procedure I am calling:

create proc spx
@in int = null output,
@vc nvarchar(10) = null output,
@dt datetime = null output
as
select
@in = null,
@vc = null,
@dt = null
return

The variables to which the three output parameters return their values have a data type of Object. The task runs fine when the integer or datetime parameters are used, and the variables can be identified as null using IsDBNull. But as soon as the nvarchar (or varchar) parameter is included, the task fails with this message:

"The incoming tabular data stream (TDS) remote procedure call (RPC) protocol stream is incorrect. Parameter 1 ("@vc"): Data type 0xE7 has an invalid data length or metadata length."

I have seen a couple of postings that sound similar to this problem, but so far I have found no resolution. Any advice would be much appreciated.

Thanks,

Ron Rice







View 11 Replies View Related

Deleted Event On Sqldatasource And Output Parameters... Always NULL!!

Apr 18, 2007

I have an event:
Private Sub SqlDataSourceIncome_Deleted(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceStatusEventArgs) Handles SqlDataSourceIncome.Deleted
Dim command As SqlClient.SqlCommand
command = e.Command
If command.Parameters("@nReturnCode").Value <> 0 Then
    DROPDEAD()
End If
That  fires from:
<DeleteParameters>
<asp:Parameter Name="nDeletebyId" Type="Int64" />
<asp:Parameter Name="nOtherId" Type="Int64" />
<asp:Parameter Direction="Output" Name="nReturnCode" Type="Int64" />
<asp:Parameter Direction="Output" Name="nReturnId" Type="Int64" />
</DeleteParameters>
End Sub
 
When I:
GridViewIncome.DeleteRow(GridViewIncome.SelectedRow.RowIndex)
But nReturnCode is ALWAYS NULL... I even did a stored procedure that just:
ALTER PROCEDURE [dbo].[sp_nDeletebyId]
 @nReturnCode bigint output,
@nReturnId bigint output AS
SET @nReturnCode = 0
SET @nReturnId = 0
And STILL got nothing but the NULLS... the insert & update stuff works fine, with identical code... it's just the DELETED event that I can't seem to knock.  Has anyone seen this before?  The above sample stored proc did return 0 when executed one the server...
and, BTW, the row is deleted!
 
Chip Kigar
 

View 2 Replies View Related

Return Output Values From View

Jan 2, 2006

How can I return values from my SQL view back into my aspx page and shove each returned value into variables I define for certain returned fields?

View 2 Replies View Related

Using NOT IN With Null Values

May 19, 2008

Hi, I ve a table,  I want to fetch certain rows based on the value of a Column. That column is nullable, and contains NULL values.I used the following query,SELECT Col_A FROM TABLE1 WHERE SOME_ID = 1317 AND Col_B NOT IN (8,9) Here,  Col_B contains NULL values too. I need to fetch all rows where Col_B is not 8 or 9.Now, if I use "NOT IN", it does not work. I tried reading on it and got to know why it does not work. Even "NOT EXISTS" does not help. But still I've to fetch my values. How do I do that?Thanks & Regards,Jahanzeb        

View 6 Replies View Related

SQL Null Values In VB

Apr 10, 2006

I have tried doing a search, as I figured this would be a common problem, but I wasn't able to find anything.  I know that my SP is functional because when I use VWD execute the query outside of the webpage, I get the correct results -however I have to ensure that a field is either entered, or set to <NULL>.  In my SET's I want it to use the wildcards.
What I want is to do a search (plenty of existing topics on that, however none were of help to me).  If a field is entered, then it is included in the search.  Otherwise it should be ignored.  In my VB I have the standard stored procedure call, passing in values to all of the parameters in the stored proc below:
CREATE PROCEDURE dbo.SearchDog@tagnum int,@ownername varchar(50), @mailaddress varchar(50),@address2 varchar(50),@city varchar(50),@telephone varchar(50),@doggender varchar(50),@dogbreed varchar(50),@dogage varchar(50),@dogcolour varchar(50),@dogname varchar(50),@applicationdate varchar(50)AS IF @tagnum=-1  SET @tagnum=NULL  SET @ownername = '%'+@ownername+'%'  SET @mailaddress = '%'+@mailaddress+'%'  SET @address2='%'+@address2+'%'  SET @city = '%'+@city+'%'  SET @telephone='%'+@telephone+'%'  SET @dogcolour='%'+@dogcolour+'%'  SET @dogbreed='%'+@dogbreed+'%'  SET @dogage='%'+@dogage+'%'  SET @doggender='%'+@doggender+'%'  SET @dogname='%'+@dogname+'%'  SET @applicationdate='%'+@applicationdate+'%'
 SELECT DISTINCT  * FROM DogRegistry WHERE (  TagNum = @tagnum OR  OwnerName LIKE @ownername OR  MailAddress LIKE @mailaddress OR  Address2 LIKE @address2 OR  City LIKE @city OR  Telephone LIKE @telephone OR  DogGender LIKE @doggender OR  DogBreed LIKE @dogbreed OR  DogAge LIKE @dogage OR  DogColour LIKE @dogcolour OR  DogName LIKE @dogname OR  ApplicationDate LIKE @applicationdate  ) AND TagNum > 0GO
I don't know why it is creating links inside my SP -ignore them.  TagNum is the primary key, if that makes a difference.
On the webpage, it ONLY works when every field has been filled (and then it will only return 1 row, as it should, given the data entered).  Debugging has shown that when nothing is entered it passes "".
Any ideas?

View 9 Replies View Related

Null Values

Jun 29, 2000

I am trying to retrieve data from two different tables. One of the tables has more than 20 columns some of which are null. I would like to retrieve data from both tables excluding the columns which have null values. How do I do this?

View 3 Replies View Related

SUM When There Are Null Values.

Nov 2, 2007

Would this take care of null values in either a.asset or b.asset?

SELECT convert(decimal(15,1),(sum(isnull(a.asset,0))/1000.0)+(sum(isnull(b.asset,0))/1000.0)) as total_assets

What's throwing me off is that there are multiple a.asset or b.asset for each unique ID. It seems to work, but I'm not following the logic too well. If I were doing this in another language, I would loop through, summing a.asset and b.asset wherever it's not null for each unique ID.

View 8 Replies View Related

Null Values

Jan 16, 2006

Hi,

How can I use "Derived Column" to check if a Datetime value is null or not and if null to insert  00/00/00 instead. ?

The background being that while using a "Derived Column" to change a Column from a (DT_DATE) to a (DT_DBTIMESTAMP) everytime I get a null value it see's it as a error.

And the column in particular has ~ 37 K blank / null fields so Im getting a lot of errors

So far I have tried to use something like

ISNULL([Column 34])

Or

SELECT ISNULL(ID, '00/00/0000') FROM [Column 34]

Or


SELECT ISNULL(au_id, '00/00/0000 00:00') AS ssn
FROM [Column 34

but none seems to work [Column 34] being the offending column.

What a normally use is just a simple "(DT_DBTIMESTAMP)[Column 34]"
in the expression column, which seems to work well, but here I get alot of errors

Any ideas?

View 2 Replies View Related

Null Values

Apr 20, 2007

I set up a new SQL database file, in that file I allowed nulls, When I went through code to save the record, the exception is saying it doesnt allow nulls.



Before I get to involved with SQL, is it a bad practice to use nulls?



If it is what do you enter in place of the null value,

which will lead to more code, right?



Davids Learning SQL

View 13 Replies View Related

Please Help! Cannot See Values In Output Params From SQL Server 2000 Using C# / ASP.NET

May 26, 2004

Hi,

I've got the following C# function to add a customer record to the database. The record gets added without any problems but the OUTPUT PARAMETER (Parameter[10]) is always NULL and I can't see why. I'm also using the Microsoft Data Application Block.

Here's the C# function:

public void SaveCustomer(int customerId,string customerName,string address1,
string address2,
string town,
string county,
string postcode,
string webSiteAddress,
string mainTelNo,
string mainFaxNo)

{
try
{
SqlParameter[] parameters = DA.SqlHelperParameterCache.GetSpParameterSet(this.ConnectionString,"UpdateCustomer");
parameters[0].Value = customerId;
parameters[1].Value = customerName;
parameters[2].Value = address1;
parameters[3].Value = address2;
parameters[4].Value = town;
parameters[5].Value = county;
parameters[6].Value = postcode;
parameters[7].Value = webSiteAddress;
parameters[8].Value = mainTelNo;
parameters[9].Value = mainFaxNo;
parameters[10].Direction = ParameterDirection.Output;

int RetVal = DA.SqlHelper.ExecuteNonQuery(this.Connection,"UpdateCustomer",parameters);

if (RetVal > 0)
{
int Key = Convert.ToInt32(parameters[10].Value.ToString());
}

}
catch (Exception ex)
{
throw new Exception(ex.Message.ToString(), ex);
}

}


And here's the SQL Server 2000 Stored Procedure:


CREATE PROCEDURE UpdateCustomer

@CustomerId int,
@CustomerName varchar(100),
@Address1 varchar(50),
@Address2 varchar(50),
@Town varchar(30),
@County varchar(30),
@PostCode varchar(10),
@WebSite varchar(50),
@MainTelNo varchar(15),
@MainFaxNo varchar(15),
@ReturnValue int OUTPUT

AS

IF @CustomerId = 0
BEGIN
INSERT INTO Customer
(CustomerName, Address1, Address2, Town, County, Postcode, WebSite, MainTelNo, MainFaxNo)
VALUES(@CustomerName, @Address1, @Address2, @Town, @County, @Postcode, @WebSite, @MainTelNo, @MainFaxNo)

IF @@ERROR = 0
BEGIN
SELECT @ReturnValue = @@IDENTITY
END
ELSE
BEGIN
SELECT @ReturnValue = -1
END

END
ELSE
BEGIN
UPDATE Customer
SETCustomerName = @CustomerName,
Address1 = @Address1,
Address2 = @Address2,
Town = @Town,
County = @County,
Postcode = @Postcode,
WebSite = @WebSite,
MainTelNo = @MainTelNo,
MainFaxNo = @MainFaxNo
WHERECustomerId = @CustomerId

IF @@ERROR = 0
BEGIN
SELECT @ReturnValue = @CustomerId
END
ELSE
BEGIN
SELECT @ReturnValue = -1
END
END



Any help would be appreciated as it's starting to drive me mad now!!

View 7 Replies View Related

Truncated OUTPUT Stored Procedure Values

Apr 11, 2006

Hi,I created the SQL 2005 stored procedure below:CREATE PROCEDURE [dbo].[STP_val_deliverable_path]@s_no smallint,@deliverable_path nvarchar(255) OUTPUTWhen I run in ASP.NET 2005 the stored procedure from server explorer Iget the value 'X:my directory.......'.When I run the procedure from code:   Dim var_deliverable_path As String       Dim cmm_select As New SqlCommand("STP_val_deliverable_path",connection)       cmm_select.CommandType = Data.CommandType.StoredProcedure       var_param = New SqlParameter       var_param.ParameterName = "deliverable_path"       var_param.Direction = Data.ParameterDirection.Output       var_param.Value = "C:"       cmm_select.Parameters.Add(var_param)       cmm_select.Connection.Open()       cmm_select.ExecuteNonQuery()       cmm_select.Connection.Close()       var_deliverable_path =CType(cmm_select.Parameters("deliverable_path").Value, String)The var_deliverable_path has the value of 'X' only, not the wholestring.What could be the problem ?

View 2 Replies View Related

Dealing With Null Values

Jul 31, 2006

hi ive got a inert sub where i grab values from text boxes etxthe values are passed to a stored procedure however , one of these fields is a date field , but the field is not required ...so on this line if the date text box is left blank i get an error , not a valid date    .Parameters.Add("@actiondate", SqlDbType.DateTime).Value = txtActionDate.Texti have tried ( the actiondate field can take nulls ..)if txtActionDate="" then    .Parameters.Add("@actiondate", SqlDbType.DateTime).Value = nothing else.Parameters.Add("@actiondate", SqlDbType.DateTime).Value = txtActionDate.Textend if but this doesnt workwhat is the best way of allowing blank values to be passed to the stored procedure( it doesnt fall over with normal text / varchar fields ) thanks

View 1 Replies View Related

SQLDataSource And Null Values

Dec 20, 2006

I have a sproce that accepts null for one of its parameters I can execute the sproce and enter null and it works fine, it returns all rows. When I try doing this with my GridView and the SQLDataSource it does not work. I need some help in understanding how the SQLDatasource wants a null. Here is what the parameter row of the SQLDataSource looks like.
<asp:ControlParameter ControlID="EnteredByText" DefaultValue="Null" Name="EnteredBy" PropertyName="Text"
Type="String" ConvertEmptyStringToNull="true" />
In my sproce I have setup the parameter as follows;
@EnteredBy Nvarchar(50)=Null
In my WHERE Clause I have:
WHERE (tblClient.EnteredBy = @EnteredBy OR @EnteredBy IS NULL)

View 3 Replies View Related

How To Check For NULL Values In T-SQL

Jan 19, 2007

How can I check on NULL values in a Select statement?
SELECT ID FROM TabelWHERE somecolumn <> NULL??

View 2 Replies View Related

Querying When Some Values Are Null

Mar 5, 2007

I wonder if someone out there can help me. I am writing an ASP application to query a MSSQL database. The users will be able to use one or all of 4 columns. There may be time when the columns are empty (null). How can I write a select query to ignore null values? A rough example of what I am talking about it below.
select * from table where value1='something' value2=<null> value3='something' value4=<null>
 I would like to ignore the null values so that in effect the statement would just do the following.
select * from table where value1='something' and value3='something'
 I realize my syntax is wrong but I think you get the idea. Any thoughts?

View 5 Replies View Related

Selecting Null Values

Mar 12, 2007

I have a stored procedure that allows users to select addresses based on partially supplied information from the user.  My procedure seems to work fine in all but a few cases. If a user decides to select all the rows for a particular country the procedure below does not return any rows even if the rows exist.  I tracked this down to the fact that for Non US countries I set both the StateCode and Country Code to nulls. .
 Below is a partial version of my code.  Can anyone show me how I can do a "Like" Search even if some of the fields in the row contain null values?
Thanks
 1 CREATE PROCEDURE dbo.Addresses_Like( @SendTo VarChar(50) = Null
2 , @AddressLine1 VarChar(50) = Null
3 , @AddressLine2 VarChar(50) = Null
4 , @City VarChar(50) = Null
5 , @StateCode VarChar(2) = Null
6 , @ZipCode VarChar(10) = Null
7 , @CountryCode VarChar(2) = Null)
8
9
10 Declare @SearchSendTo VarChar(50)
11 Declare @SearchAddressLine1 VarChar(50)
12 Declare @SearchAddressLine2 VarChar(50)
13 Declare @SearchCity VarChar(50)
14 Declare @SearchStateCode VarChar(2)
15 Declare @SearchZipCode VarChar(10)
16 Declare @SearchCountryCode VarChar(2)
17
18 If (@SendTo Is Null)
19 Set @SearchSendTo = ""
20 Else
21 Set @SearchSendTo = @SendTo
22
23 If (@AddressLine1 Is Null)
24 Set @SearchAddressLine1 = ""
25 Else
26 Set @SearchAddressLine1 = @AddressLine1
27
28 If (@AddressLine2 Is Null)
29 Set @SearchAddressLine2 = ""
30 Else
31 Set @SearchAddressLine2 = @AddressLine2
32
33 If (@City Is Null)
34 Set @SearchCity = ""
35 Else
36 Set @SearchCity = @City
37
38 If (@StateCode Is Null)
39 Set @SearchStateCode = ""
40 Else
41 Set @SearchStateCode = @StateCode
42
43 If (@ZipCode Is Null)
44 Set @SearchZipCode = ""
45 Else
46 Set @SearchZipCode = @ZipCode
47
48 If (@CountryCode Is Null)
49 Set @SearchCountryCode = ""
50 Else
51 Set @SearchCountryCode = @CountryCode
52
53
54 Select AddressID
55 , SendTo
56 , AddressLine1
57 , AddressLine2
58 , City
59 , StateCode
60 , ZipCode
61 , CountryCode
62 , RowVersion
63 , LastChangedDateTime
64 , OperID
65 From Addresses
66 Where SendTo Like RTrim(LTrim(@SearchSendTo)) + "%"
67 And AddressLine1 Like RTrim(LTrim(@SearchAddressLine1)) + "%"
68 And AddressLine2 Like RTrim(LTrim(@SearchAddressLine2)) + "%"
69 And City Like RTrim(LTrim(@SearchCity)) + "%"
70 And StateCode Like RTrim(LTrim(@SearchStateCode)) + "%"
71 And ZipCode Like RTrim(LTrim(@SearchZipCode)) + "%"
72 And CountryCode Like RTrim(LTrim(@SearchCountryCode)) + "%"
73 Order By CountryCode, City, AddressLine1, AddressLine2, SendTo
 

View 6 Replies View Related

Finding NULL Values

Apr 10, 2007

I want to write a query to bring out any records in a table
where any of its fields contain a null value.  I could do it in this way:
 
select    *

from    
customers
where   name is
null
or         role
 is null
or         email
is null
u003c/p>u003cp styleu003d"margin:0cm 0cm 0pt">u003cfont faceu003d"Times New Roman" sizeu003d"3">u003cfont coloru003d"#000000">However I want to perform a similar function for a number of tables and the method above would mean more sql and maintenance.u003cspan>Â u003c/span>I was hoping there was a simple way to do the same thingu003cspan> ie find any rows with a blank fieldu003c/span>?u003cspan>u003cfont faceu003d"Arial" sizeu003d"2">Â u003c/font>u003c/span>u003c/font>u003c/font>u003c/p>u003c/span>u003c/font>u003c/div>",0]
);
D(["ce"]);

//--> 
However I want to perform a similar function for a
number of tables and the method above would mean more sql and maintenance.  I was hoping there was a simple way to
do the same thing ie find any rows with a blank
field?

View 4 Replies View Related

Returning Null Values

Jun 4, 2007

I have a simple table on my webpage which shows data from my database.
It all worked fine apart from one part. I wanted the select statement to select only NULL values from a column, as these are classed as open queries. Once I have closed the query a 0 or 1 will automatically be posted and will no longer have a NULL value.
I have a simple select statement (which I will post on here when I log in with my work computer) and at the end I have a WHERE Column = NULL. I have also tried WHERE column <> 0.0 AND column <>1.0 and that did not work.
If I only did WHERE column <> 1.0, i only get the 0.0 results and none of the NULL results, but if I have no WHERE statement I get all the results including the NULL values.
 
Oliver

View 6 Replies View Related

How To Deal With Null Values

Mar 1, 2008

Hi I have a table in my database and one of the columns is called 'Month'. Here only one month is inserted according to what the user selects from a dro down list.
WHat i want to be able to do is find the average of the column 'ScoreOut' on a month by month basis. My code works fine if th database contains at least one row with every month of the year represented. I run into problems when one of the months is not represented. here is my code:string month = "February";
SqlConnection myConn = new SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True;User Instance=True");String selectCommand = "Select AVG(CAST(ScoreOut as float)) from tblRound where Name = '" + lblName.Text + "' AND Month = '" + month + "'";
SqlCommand myCmd = new SqlCommand(selectCommand, myConn);SqlDataAdapter da = new SqlDataAdapter(myCmd);DataTable dt = new DataTable();
 
da.Fill(dt);
myConn.Open();
myCmd.ExecuteNonQuery();string info = String.Format("{0:0.00}", Convert.ToDecimal(myCmd.ExecuteScalar()));
myConn.Close();
lblHole2.Text = info;
 
 
 
Does anyone know how to get around this problem. If a month is not represented, i would like the label lblHole2.text to be equal to 0.
 
thanks   

View 4 Replies View Related

Null Values In Smalldatetime

Feb 24, 2004

Hi,

I am having a column subdate as smalldatetime.

The field can have null values. But I am not able to insert null values into the database.
i tried using subdate="". But it inserts some min value of my calendar popup.

Is there a way that i could insert null values into smalldatetime field of the SQl database.

Thanks,
-sriram

View 9 Replies View Related







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