Showing posts with label empty. Show all posts
Showing posts with label empty. Show all posts

Wednesday, March 28, 2012

Numbering in SQL

I have table with 10-20 rows with field P6 which is empty. I want to
update numbers to P6 starting 1 and increasing by 1. I suppose it is
done by triggers but I don't know how to do that. Help :-)is this as 1 off or every time you INSERT a record?

--
--
Jack Vamvas
___________________________________
Receive free SQL tips - www.ciquery.com/sqlserver.htm
___________________________________

<lemes_m@.yahoo.com> wrote in message
news:1148037597.406952.273140@.j33g2000cwa.googlegr oups.com...
> I have table with 10-20 rows with field P6 which is empty. I want to
> update numbers to P6 starting 1 and increasing by 1. I suppose it is
> done by triggers but I don't know how to do that. Help :-)|||Make the column a identity value, this way it is incremented with every
insert:

int IDENTITY (1, 1)|||lemes_m@.yahoo.com (lemes_m@.yahoo.com) writes:
> I have table with 10-20 rows with field P6 which is empty. I want to
> update numbers to P6 starting 1 and increasing by 1. I suppose it is
> done by triggers but I don't know how to do that. Help :-)

Without further knowledge about the table it is difficult to give
advice. And if the rest of the data is not unique, it's getting sort
of ugly.

For a one-off you could do:

DECLARE @.i int
SELECT @.i = 1
-- SET ROWCOUNT 1 Use this on SQL 2000.
WHILE EXISTS (SELECT * FROM tbl WHERE P6 IS NULL)
BEGIN
UPDATE /* TOP(1) */ tbl -- Remove comment for SQL 2005.
SET P6 = @.i

SELECT @.i = @.i + 1
END
-- SET ROWCOUNT 0 again, for SQL 2000.

But I would not like to see this code in a trigger.

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx|||>> have table with 10-20 rows with field [sic] P6 which is empty [sic]. <<

You have NEVER written SQL before, have you? Columsn are not fields
and we have NULLs, not the empty spreadsheet cells you assume. TOTALLY
WRONG MINDSET!

>> I want to update numbers to P6 starting 1 and increasing by 1. <<

That is a SEQUENTAL MAGNETIC TAPE FILE and you are tryignto write
1950's code in SQL! It has northing whatsoever to do with RDBMS.
Tables have no ordering by definition. This is soooooo wrong ...|||Geeesh!!! You can insert a set at a time, so adding one to a previous
value makes no sense. Doesn't anyone go to RDBMS classes any more?|||>> Make the column a identity value, this way it is incremented with every insert: <<

Always go for the proprietary and most non-relational kludge? LET'S
FINBD OUT WHAT HE IS REALLY TRYIGN TO DO BEFORE WE POST ANYTHING ELSE.

Okay, lemes_m@.yahoo.com , why do you want to destroy the relational
model? What is your business goal?|||Hi Lemes,

Check out http://blogs.msdn.com/sqlcat/archiv.../10/572848.aspx it has
good examples of how to do this.

Tony.

--
Tony Rogerson
SQL Server MVP
http://sqlblogcasts.com/blogs/tonyrogerson - technical commentary from a SQL
Server Consultant
http://sqlserverfaq.com - free video tutorials

<lemes_m@.yahoo.com> wrote in message
news:1148037597.406952.273140@.j33g2000cwa.googlegr oups.com...
>I have table with 10-20 rows with field P6 which is empty. I want to
> update numbers to P6 starting 1 and increasing by 1. I suppose it is
> done by triggers but I don't know how to do that. Help :-)

Monday, March 12, 2012

Number format to return 0 when empty?

My client has several issues with the number formating in the reports.
They want to have a space between 1 000 and no decimals. First I created a
custom format, but today I noticed I could get the same result with N0.
Anyway, N0 format will not show empty numbers, it just leaves the cell
blank. But my client now wants to have a 0 instead of blank. Is it possible?
Kaisa M. LindahlTry using =IIF(<Your number field> Is Nothing, 0, <Your number field>) as
the value expression.
--
This posting is provided "AS IS" with no warranties, and confers no rights.
"Kaisa M. Lindahl" <kaisaml@.hotmail.com> wrote in message
news:e$Sm76V%23EHA.2076@.TK2MSFTNGP15.phx.gbl...
> My client has several issues with the number formating in the reports.
> They want to have a space between 1 000 and no decimals. First I created a
> custom format, but today I noticed I could get the same result with N0.
> Anyway, N0 format will not show empty numbers, it just leaves the cell
> blank. But my client now wants to have a 0 instead of blank. Is it
> possible?
> Kaisa M. Lindahl
>|||Yes, I've figured that one out.
Problem is, I'd have to do it on aprox. 20 cells in each report (> 10 so
far), all with different field names... If there are any other solutions,
I'd be very happy to hear it.
Kaisa M. Lindahl
"Fang Wang (MSFT)" <fangw@.microsoft.com> wrote in message
news:u907lUd#EHA.936@.TK2MSFTNGP12.phx.gbl...
> Try using =IIF(<Your number field> Is Nothing, 0, <Your number field>) as
> the value expression.
> --
> This posting is provided "AS IS" with no warranties, and confers no
rights.
> "Kaisa M. Lindahl" <kaisaml@.hotmail.com> wrote in message
> news:e$Sm76V%23EHA.2076@.TK2MSFTNGP15.phx.gbl...
> > My client has several issues with the number formating in the reports.
> > They want to have a space between 1 000 and no decimals. First I created
a
> > custom format, but today I noticed I could get the same result with N0.
> > Anyway, N0 format will not show empty numbers, it just leaves the cell
> > blank. But my client now wants to have a 0 instead of blank. Is it
> > possible?
> >
> > Kaisa M. Lindahl
> >
> >
>|||I'm sorry, but there is no "easier" solution than using IIF for this
scenario.
--
This posting is provided "AS IS" with no warranties, and confers no rights.
"Kaisa M. Lindahl" <kaisaml@.hotmail.com> wrote in message
news:ORxJ1Jh%23EHA.3988@.TK2MSFTNGP11.phx.gbl...
> Yes, I've figured that one out.
> Problem is, I'd have to do it on aprox. 20 cells in each report (> 10 so
> far), all with different field names... If there are any other solutions,
> I'd be very happy to hear it.
> Kaisa M. Lindahl
> "Fang Wang (MSFT)" <fangw@.microsoft.com> wrote in message
> news:u907lUd#EHA.936@.TK2MSFTNGP12.phx.gbl...
> > Try using =IIF(<Your number field> Is Nothing, 0, <Your number field>)
as
> > the value expression.
> >
> > --
> > This posting is provided "AS IS" with no warranties, and confers no
> rights.
> >
> > "Kaisa M. Lindahl" <kaisaml@.hotmail.com> wrote in message
> > news:e$Sm76V%23EHA.2076@.TK2MSFTNGP15.phx.gbl...
> > > My client has several issues with the number formating in the reports.
> > > They want to have a space between 1 000 and no decimals. First I
created
> a
> > > custom format, but today I noticed I could get the same result with
N0.
> > > Anyway, N0 format will not show empty numbers, it just leaves the cell
> > > blank. But my client now wants to have a 0 instead of blank. Is it
> > > possible?
> > >
> > > Kaisa M. Lindahl
> > >
> > >
> >
> >
>

Nulls in SQL 2005

Hello,

I have a varchar(20) field which stores a value or empty string.

I have noticed that if the value is NULL and I use is null in my query, the query runs very fast. However If I also include in my query a check for an empty string (len(rtrim(field)) = 0) the query is much slower.

Is it a good idea to force the empty strings to null and if Yes is there an automatic way in sql 2005 (maybe a trigger) to update all empty strings to null.

Thanks, I just need some advice.

Michael

The difference may be coming from the use of functions than checking for an empty string versus a null string. The optimizer cannot make use of an expression in the same way as it makes use of a field.

Using a trigger to turn blanks into null is not a bad idea, but it is not without overhead either. Also consider whether a blank string represents something different than a NULL. You might also want to revisit your data model and see whether it makes more sense to put the value in a separate table and remove the entry when it is not necessary.

|||One more option is to create computed column and index over it, but there are some requirements for that (refer for details: http://msdn2.microsoft.com/en-us/library/ms189292.aspx )|||

HI

U can also use this query

select * from table1 where col1 is null or col1 = ''

Friday, March 9, 2012

NULL vs. empty strings, SQL Server setting

Without getting into a theoretical discussion about whether it is the
right thing to do, is there a switch or flag for SQL Server 2005 to
make NULL strings be the same as empty string?
Thanks,
K Galanga
No such switch...
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"Kat" <galangkk@.sverdrup.com> wrote in message
news:1160335879.054188.203150@.i3g2000cwc.googlegro ups.com...
> Without getting into a theoretical discussion about whether it is the
> right thing to do, is there a switch or flag for SQL Server 2005 to
> make NULL strings be the same as empty string?
> Thanks,
> K Galanga
>
|||Kat wrote:
> Without getting into a theoretical discussion about whether it is the
> right thing to do, is there a switch or flag for SQL Server 2005 to
> make NULL strings be the same as empty string?
> Thanks,
> K Galanga
Depending on what your intention is, maybe you could make a column NOT
NULL and add a default:
ALTER TABLE tbl ADD CONSTRAINT df_tbl_col DEFAULT ('') FOR col;
David Portas, SQL Server MVP
Whenever possible please post enough code to reproduce your problem.
Including CREATE TABLE and INSERT statements usually helps.
State what version of SQL Server you are using and specify the content
of any error messages.
SQL Server Books Online:
http://msdn2.microsoft.com/library/ms130214(en-US,SQL.90).aspx
|||Hello David,
What do you mean by "the same", you can get a NULL to act as a '' in concatenation
,however comparisions i.e. NULL = '' will always be inconclusive.
set concat_null_yields_null off
is what you want to achieve the former
Simon Sabin
SQL Server MVP
http://sqlblogcasts.com/blogs/simons

> Kat wrote:
> Depending on what your intention is, maybe you could make a column NOT
> NULL and add a default:
> ALTER TABLE tbl ADD CONSTRAINT df_tbl_col DEFAULT ('') FOR col;
> --
> David Portas, SQL Server MVP
> Whenever possible please post enough code to reproduce your problem.
> Including CREATE TABLE and INSERT statements usually helps.
> State what version of SQL Server you are using and specify the content
> of any error messages.
> SQL Server Books Online:
> http://msdn2.microsoft.com/library/ms130214(en-US,SQL.90).aspx --
>
|||Hi Kat
As others have said, there is no server-wide switch.
There are some things you can do in different environments. For the purpose
of concatenation, you can treat NULLs as empty strings with
SET CONCAT_NULL_YIELDS_NULL OFF
However, that is a session setting, and will not affect anything other than
the current connection.
If you have a variable or parameter, and you want to treat NULL as if it is
an empty string, you can use the ISNULL function in your queries. But that
is valid just for a single expression
HTH
Kalen Delaney, SQL Server MVP
http://sqlblog.com
"Kat" <galangkk@.sverdrup.com> wrote in message
news:1160335879.054188.203150@.i3g2000cwc.googlegro ups.com...
> Without getting into a theoretical discussion about whether it is the
> right thing to do, is there a switch or flag for SQL Server 2005 to
> make NULL strings be the same as empty string?
> Thanks,
> K Galanga
>

NULL vs. empty strings, SQL Server setting

Without getting into a theoretical discussion about whether it is the
right thing to do, is there a switch or flag for SQL Server 2005 to
make NULL strings be the same as empty string?
Thanks,
K GalangaNo such switch...
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"Kat" <galangkk@.sverdrup.com> wrote in message
news:1160335879.054188.203150@.i3g2000cwc.googlegroups.com...
> Without getting into a theoretical discussion about whether it is the
> right thing to do, is there a switch or flag for SQL Server 2005 to
> make NULL strings be the same as empty string?
> Thanks,
> K Galanga
>|||Kat wrote:
> Without getting into a theoretical discussion about whether it is the
> right thing to do, is there a switch or flag for SQL Server 2005 to
> make NULL strings be the same as empty string?
> Thanks,
> K Galanga
Depending on what your intention is, maybe you could make a column NOT
NULL and add a default:
ALTER TABLE tbl ADD CONSTRAINT df_tbl_col DEFAULT ('') FOR col;
--
David Portas, SQL Server MVP
Whenever possible please post enough code to reproduce your problem.
Including CREATE TABLE and INSERT statements usually helps.
State what version of SQL Server you are using and specify the content
of any error messages.
SQL Server Books Online:
http://msdn2.microsoft.com/library/ms130214(en-US,SQL.90).aspx
--|||Hi Kat
As others have said, there is no server-wide switch.
There are some things you can do in different environments. For the purpose
of concatenation, you can treat NULLs as empty strings with
SET CONCAT_NULL_YIELDS_NULL OFF
However, that is a session setting, and will not affect anything other than
the current connection.
If you have a variable or parameter, and you want to treat NULL as if it is
an empty string, you can use the ISNULL function in your queries. But that
is valid just for a single expression
--
HTH
Kalen Delaney, SQL Server MVP
http://sqlblog.com
"Kat" <galangkk@.sverdrup.com> wrote in message
news:1160335879.054188.203150@.i3g2000cwc.googlegroups.com...
> Without getting into a theoretical discussion about whether it is the
> right thing to do, is there a switch or flag for SQL Server 2005 to
> make NULL strings be the same as empty string?
> Thanks,
> K Galanga
>

NULL vs. empty strings, SQL Server setting

Without getting into a theoretical discussion about whether it is the
right thing to do, is there a switch or flag for SQL Server 2005 to
make NULL strings be the same as empty string?
Thanks,
K GalangaNo such switch...
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"Kat" <galangkk@.sverdrup.com> wrote in message
news:1160335879.054188.203150@.i3g2000cwc.googlegroups.com...
> Without getting into a theoretical discussion about whether it is the
> right thing to do, is there a switch or flag for SQL Server 2005 to
> make NULL strings be the same as empty string?
> Thanks,
> K Galanga
>|||Kat wrote:
> Without getting into a theoretical discussion about whether it is the
> right thing to do, is there a switch or flag for SQL Server 2005 to
> make NULL strings be the same as empty string?
> Thanks,
> K Galanga
Depending on what your intention is, maybe you could make a column NOT
NULL and add a default:
ALTER TABLE tbl ADD CONSTRAINT df_tbl_col DEFAULT ('') FOR col;
David Portas, SQL Server MVP
Whenever possible please post enough code to reproduce your problem.
Including CREATE TABLE and INSERT statements usually helps.
State what version of SQL Server you are using and specify the content
of any error messages.
SQL Server Books Online:
http://msdn2.microsoft.com/library/ms130214(en-US,SQL.90).aspx
--|||Hello David,
What do you mean by "the same", you can get a NULL to act as a '' in concate
nation
,however comparisions i.e. NULL = '' will always be inconclusive.
set concat_null_yields_null off
is what you want to achieve the former
Simon Sabin
SQL Server MVP
http://sqlblogcasts.com/blogs/simons

> Kat wrote:
>
> Depending on what your intention is, maybe you could make a column NOT
> NULL and add a default:
> ALTER TABLE tbl ADD CONSTRAINT df_tbl_col DEFAULT ('') FOR col;
> --
> David Portas, SQL Server MVP
> Whenever possible please post enough code to reproduce your problem.
> Including CREATE TABLE and INSERT statements usually helps.
> State what version of SQL Server you are using and specify the content
> of any error messages.
> SQL Server Books Online:
> http://msdn2.microsoft.com/library/ms130214(en-US,SQL.90).aspx --
>|||Hi Kat
As others have said, there is no server-wide switch.
There are some things you can do in different environments. For the purpose
of concatenation, you can treat NULLs as empty strings with
SET CONCAT_NULL_YIELDS_NULL OFF
However, that is a session setting, and will not affect anything other than
the current connection.
If you have a variable or parameter, and you want to treat NULL as if it is
an empty string, you can use the ISNULL function in your queries. But that
is valid just for a single expression
HTH
Kalen Delaney, SQL Server MVP
http://sqlblog.com
"Kat" <galangkk@.sverdrup.com> wrote in message
news:1160335879.054188.203150@.i3g2000cwc.googlegroups.com...
> Without getting into a theoretical discussion about whether it is the
> right thing to do, is there a switch or flag for SQL Server 2005 to
> make NULL strings be the same as empty string?
> Thanks,
> K Galanga
>

Wednesday, March 7, 2012

Null valus in a select

How do I check of null in a select clause and replace them with space/empty
string?SELECT COALESCE(col_x, '') AS col_x
FROM your_table ;
--
David Portas
SQL Server MVP
--|||David Portas wrote:
> SELECT COALESCE(col_x, '') AS col_x
> FROM your_table ;
or
SELECT ISNULL(col_x, '') AS col_x
FROM your_table
robert|||That kind of works, except if the column is a smallint I get 0 instead of ''
"David Portas" wrote:
> SELECT COALESCE(col_x, '') AS col_x
> FROM your_table ;
> --
> David Portas
> SQL Server MVP
> --
>|||That kind of works, except if the column is a smallint I get 0 instead of ''
"Robert Klemme" wrote:
> David Portas wrote:
> > SELECT COALESCE(col_x, '') AS col_x
> > FROM your_table ;
> or
> SELECT ISNULL(col_x, '') AS col_x
> FROM your_table
> robert
>|||Arne,
An expression in the Selection List can only return the predefined data
type. If you want to return a smallint, then by definition, you cannot
return an empty string. If returning a string works for you, then you
can use this:
SELECT COALESCE(CAST(col_x AS VARCHAR(11)), '') AS col_x
FROM your_table
Gert-Jan
Arne wrote:
> That kind of works, except if the column is a smallint I get 0 instead of ''
> "Robert Klemme" wrote:
> > David Portas wrote:
> > > SELECT COALESCE(col_x, '') AS col_x
> > > FROM your_table ;
> >
> > or
> >
> > SELECT ISNULL(col_x, '') AS col_x
> > FROM your_table
> >
> > robert
> >
> >|||Try this.
SELECT ISNULL(CONVERT(VARCHAR(5),col_x), '') AS col_x FROM your_table
"Arne" wrote:
> That kind of works, except if the column is a smallint I get 0 instead of ''
>
> "Robert Klemme" wrote:
> > David Portas wrote:
> > > SELECT COALESCE(col_x, '') AS col_x
> > > FROM your_table ;
> >
> > or
> >
> > SELECT ISNULL(col_x, '') AS col_x
> > FROM your_table
> >
> > robert
> >
> >

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?

Use the following in the field (default value) property

('')

Regards

|||I tried that and it didn't work.|||Just to get your point, did you mean that you want to place a default empty string?|||Smiling is correct, that is how you do it. When you say "it didn't work", perhaps you mean it didn't do what you wanted/expected it to, but that is how you define a default of a zero-length string (from within management studio).|||

That's what I thought too. I tried it again and it does work. I think what was going on is I had the table definition open and saved it but it really did not save. So I closed the defintion window and tried it and it works.

Thanks

|||Whats even more interesting it does NOT work when using the FormView control in ASP.NET 2.0 but if I enter the data directly into the table using the server explorer it does work.

???|||Does it show NULL value though?|||

YES, when viewing the data in the database server explorer the value is NULL even though the default value is ''.

Like I said entering data directly in the server explorer it works, when using a FormView control it does not. When using the formview all code is generated by VisualStudio.

Here is the SQLDatasource code generated by Visual Studio...

<asp:SqlDataSource ID="SqlDataSourceUserProfile" runat="server" ConnectionString="<%$ ConnectionStrings:AEISITConnectionString %>"
DeleteCommand="DELETE FROM [UserProfile] WHERE [UserProfile_RecID] = @.UserProfile_RecID"
InsertCommand="INSERT INTO [UserProfile] ([UserID], [UserRole], [FirstName], [LastName],Email, [CampusID], [DistrictID], [RegionID], [SessionID]) VALUES (@.UserID, @.UserRole, @.FirstName, @.LastName, @.Email, @.CampusID, @.DistrictID, @.RegionID, @.SessionID)"
SelectCommand="SELECT UserProfile_RecID, UserID, UserRole, FirstName, LastName, Email, CampusID, DistrictID, RegionID, SessionID FROM UserProfile WHERE (UserProfile_RecID = @.UserProfile_RecID)"
UpdateCommand="UPDATE [UserProfile] SET [UserID] = @.UserID, [UserRole] = @.UserRole, [FirstName] = @.FirstName, [LastName] = @.LastName,Email = @.Email, [CampusID] = @.CampusID, [DistrictID] = @.DistrictID, [RegionID] = @.RegionID, [SessionID] = @.SessionID WHERE [UserProfile_RecID] = @.UserProfile_RecID">
<DeleteParameters>
<asp:Parameter Name="UserProfile_RecID" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="UserID" Type="String" />
<asp:Parameter Name="UserRole" Type="String" />
<asp:Parameter Name="FirstName" Type="String" />
<asp:Parameter Name="LastName" Type="String" />
<asp:Parameter Name="Email" Type="String" />
<asp:Parameter Name="CampusID" Type="String" />
<asp:Parameter Name="DistrictID" Type="String" />
<asp:Parameter Name="RegionID" Type="String" />
<asp:Parameter Name="SessionID" Type="String" />
<asp:Parameter Name="UserProfile_RecID" Type="Int32" />
</UpdateParameters>
<SelectParameters>
<asp:ControlParameter ControlID="UserListBox" Name="UserProfile_RecID" PropertyName="SelectedValue"
Type="Int32" />
</SelectParameters>
<InsertParameters>
<asp:Parameter Name="UserID" Type="String" />
<asp:Parameter Name="UserRole" Type="String" />
<asp:Parameter Name="FirstName" Type="String" />
<asp:Parameter Name="LastName" Type="String" />
<asp:Parameter Name="Email" Type="String" />
<asp:Parameter Name="CampusID" Type="String" />
<asp:Parameter Name="DistrictID" Type="String" />
<asp:Parameter Name="RegionID" Type="String" />
<asp:Parameter Name="SessionID" Type="String" />
</InsertParameters>
</asp:SqlDataSource>

|||

That would explain it.

If you want the default value on insert, remove all references to the field in the insertcommand. Alternatively, change the parameter's convertemptystringtonull property to false.

|||

Yes, whatMotley said is correct.

Just change the convertemptystringtonull property to false.

NULL values in XML string

Can someone tell me how to format my XML string so when I load it into my
table the field actually has a NULL value and not an empty space?
My XML string is formated like this.
<reimbursement>
<tbl_Reimbursement>
<Type10Rec Provider_Type='INSTIT' Provider_SubType='11' ReimDesc=""
Status='PMA' CreateUsr='Test' LastModDate="" LastModUsr="" ApproveDate=""/>
</tbl_Reimbursement><
The problem is that I want the ones with nothing between the doublw quotes
to get entered into the table as NULL values not empty strings. I am having
difficulty doing this. Can someone help me? Thanks in advance.>> The problem is that I want the ones with nothing between the doublw
What is the datatype of the columns in the table? Do you have a default set
for these columns, if the values are missing?Why not post the DDLs here? Are
you using OPENXML to load the data or using some other 3rd party tools?
Anith|||CREATE TABLE [tbl_Reimbursement] (
[ReimID] [int] IDENTITY (1, 1) NOT NULL ,
[RecordType] [varchar] (2) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL
CONSTRAINT [DF_Reimbursement_RecordType] DEFAULT (10),
[ActionType] [varchar] (1) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL
CONSTRAINT [DF_tbl_Reimbursement_ActionType] DEFAULT ('A'),
[Provider_Type] [varchar] (6) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[Provider_SubType] [varchar] (2) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[NetworkCode] [varchar] (4) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL
CONSTRAINT [DF_tbl_Reimbursement_NetworkCode] DEFAULT (' '),
[EffectiveDate] [datetime] NOT NULL CONSTRAINT
[DF_tbl_Reimbursement_EffectiveDate] DEFAULT ('6/1/2004'),
[ExpirationDate] [datetime] NOT NULL CONSTRAINT
[DF_tbl_Reimbursement_ExpirationDate] DEFAULT ('12/31/2099'),
[ReimDesc] [varchar] (70) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[Status] [varchar] (10) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[SubmitDate] [datetime] NULL ,
[SubmitUsr] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[ExportID] [int] NULL ,
[ExportDate] [datetime] NULL ,
[ApproveDate] [datetime] NULL ,
[ApproveUsr] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[CreateDate] [datetime] NULL CONSTRAINT [DF_tbl_Reimbursement_CreateDate]
DEFAULT (getdate()),
[CreateUsr] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[ExportSeq] [int] NULL CONSTRAINT [DF_tbl_Reimbursement_ExportSeq] DEFAULT
(1),
[LastModDate] [datetime] NULL ,
[LastModUsr] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[ReimLocked] [bit] NULL ,
[ReimLockedBy] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
CONSTRAINT [PK_Reimbursement] PRIMARY KEY CLUSTERED
(
[ReimID]
) WITH FILLFACTOR = 90 ON [PRIMARY] ,
) ON [PRIMARY]
GO
insert into tbl_Reimbursement (Provider_Type, Provider_SubType, ReimDesc,
Status, CreateUsr, LastModDate, LastModUsr, ApproveDate, ApproveUsr)
select * from OPENXML (@.idoc,'/reimbursement/tbl_Reimbursement/Type10Rec',1)
with (Provider_Type varchar(6),
Provider_SubType varchar(2),
ReimDesc varchar(70),
Status varchar(10),
CreateUsr varchar(50),
LastModDate datetime,
LastModUsr varchar(50),
ApproveDate datetime,
ApproveUsr varchar(50))
"Anith Sen" wrote:

> What is the datatype of the columns in the table? Do you have a default se
t
> for these columns, if the values are missing?Why not post the DDLs here? A
re
> you using OPENXML to load the data or using some other 3rd party tools?
> --
> Anith
>
>|||Your XML, as you posted in your initial post, is not well formed. It has no
closing tags for reimbursement node. The XML string has only eight values,
so it will insert values for only eight corresponding columns mentioned in
the INSERT statement. If the other columns are nullable, NULLs will enter
those columns. Here is the repro:
DECLARE @.x VARCHAR(500), @.idoc INT
SET @.x = '
<reimbursement>
<tbl_Reimbursement>
<Type10Rec Provider_Type="INSTIT" Provider_SubType="11" ReimDesc=""
Status="PMA" CreateUsr="Test" LastModDate="" LastModUsr="" ApproveDate=""/>
</tbl_Reimbursement>
</reimbursement>'
EXEC sp_xml_preparedocument @.idoc OUTPUT, @.x
INSERT INTO tbl
( Provider_Type, Provider_SubType, ReimDesc, Status,
CreateUsr, LastModDate, LastModUsr, ApproveDate, ApproveUsr )
SELECT * -- use column names
FROM OPENXML ( @.idoc, '/reimbursement/tbl_Reimbursement/Type10Rec', 1 )
WITH ( Provider_Type VARCHAR( 6 ),
Provider_SubType VARCHAR( 2 ),
ReimDesc VARCHAR( 70 ),
Status VARCHAR( 10 ),
CreateUsr VARCHAR( 50 ),
LastModDate DATETIME,
LastModUsr VARCHAR( 50 ),
ApproveDate DATETIME,
ApproveUsr VARCHAR( 50 ) )
EXEC sp_xml_removedocument @.idoc
Anith

Saturday, February 25, 2012

Null Values

I have run a report and then grouped values. However some of these values have a 'null' or empty value. How do i change this so that the group name is not blank.

I have tried the following but this does not help:

IF {Subset.SCHOOLCAT} = '' THEN 'other'

It simply blanks out all group names.

I am doing this report on a HEAT System and i know that the reason for this null field is that we have two types of customers and one customer type does not have this field in its tables so it returns the value as blank.

I just need to replace this empty value with a string for consistency value but cannot seem to do it.

Regards

PIF {Subset.SCHOOLCAT} = '' THEN 'other'

Instead of the above code, try the following code

IF IsNull({Subset.SCHOOLCAT}) THEN 'other'|||Many thanks - that seemed to work.

Cheers

T

null value

I have a char field which I check the "allow null" property and when I tried
to input an empty string that field, it always give me the following msg:
"You tried to assign Null value to a variable that isn't a Variant data
type"
But if I run it in an update query and I don't get the same message. I am
using SQL2000 and access 97 query. Please help. Thanks._eric clapton wrote:
> I have a char field which I check the "allow null" property and when
> I tried to input an empty string that field, it always give me the
> following msg:
> "You tried to assign Null value to a variable that isn't a Variant
> data type"
> But if I run it in an update query and I don't get the same message.
> I am using SQL2000 and access 97 query. Please help. Thanks.
You can't input a zero-length string from the GUI because Access automatically
strips trailing blanks. The append query doesn't do this which is why it works.
--
I don't check the Email account attached
to this message. Send instead to...
RBrandt at Hunter dot com

null value

I have a char field which I check the "allow null" property and when I tried
to input an empty string that field, it always give me the following msg:
"You tried to assign Null value to a variable that isn't a Variant data
type"
But if I run it in an update query and I don't get the same message. I am
using SQL2000 and access 97 query. Please help. Thanks._eric clapton wrote:
> I have a char field which I check the "allow null" property and when
> I tried to input an empty string that field, it always give me the
> following msg:
> "You tried to assign Null value to a variable that isn't a Variant
> data type"
> But if I run it in an update query and I don't get the same message.
> I am using SQL2000 and access 97 query. Please help. Thanks.
You can't input a zero-length string from the GUI because Access automatical
ly
strips trailing blanks. The append query doesn't do this which is why it wo
rks.
I don't check the Email account attached
to this message. Send instead to...
RBrandt at Hunter dot com

null value

I have a char field which I check the "allow null" property and when I tried
to input an empty string that field, it always give me the following msg:
"You tried to assign Null value to a variable that isn't a Variant data
type"
But if I run it in an update query and I don't get the same message. I am
using SQL2000 and access 97 query. Please help. Thanks.
_eric clapton wrote:
> I have a char field which I check the "allow null" property and when
> I tried to input an empty string that field, it always give me the
> following msg:
> "You tried to assign Null value to a variable that isn't a Variant
> data type"
> But if I run it in an update query and I don't get the same message.
> I am using SQL2000 and access 97 query. Please help. Thanks.
You can't input a zero-length string from the GUI because Access automatically
strips trailing blanks. The append query doesn't do this which is why it works.
I don't check the Email account attached
to this message. Send instead to...
RBrandt at Hunter dot com

Monday, February 20, 2012

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)
No doubt, fields with empty strings take up way more space than their counterparts with NULL values......... have a look at this link for an example >>http://www.sqljunkies.com/WebLog/amachanic/archive/2004/10/22/4743.aspx|||

Hi Narayanas,

Thanks for your reply and solution. Now that i know storing an empty string will take up more spaces then leaving it Null, but if i have a table which has 4-5 fields that allows Null. Then how can i leave those columns to Null if the user don't enter anything for those string fields? e.g

CREATE PROCEDURE add_row
@.field1 varchar(100),
:
@.field5 varchar(100)

AS
IF @.filed1 = ''
INSERT INTO some_table (field2, ..., field5) VALUES (@.field2, ..., @.field5)
IF @.field2 = ''
INSERT INTO some_table(field1, field3, ..., field5) VALUES (@.field1, @.field3,... , @.field5)

If i do it this way then there will be too many combinations of IF statements. Can you show me some better ways to do this?

|||Are you seriously worried, in this modern age, about the extra space taken up with an empty string vs a null? I'd be more concerned about the problems and general confusion nulls create, let alone some potential performance problems with the database has to look up the null flag. If you want to use NULLs then all well and good, but treat them as a feature not a space saving device.
|||

kakusei wrote:

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)


You cannot pass an empty string to a Database NULL because ANSI SQL NULL which is database NULL is in an UNKNOWN value not an empty string. It evaluates mathematically to a NULL but it is an UNKNOWN value determined by the creator of the database. NET value types don't accept NULL the reason for DBNULL but SQL Server value types have to accept NULL to be ANSI SQL compliant. If it is Varchar (100) you use DBNULL. Space is not important but passing a Varchar (100) column an empty string will create data consistency problems in your database. Hope this helps.|||you can set default values at the time of defining the parameters in the stored proc.

CREATE PROCEDURE add_row
@.field1 varchar(100) = NULL,
:
@.field5 varchar(100) = NULL

AS
-- so you would need one insert statement.If there is a value in the variable
-- that will be inserted else null.
INSERT INTO some_table (field2, ..., field5) VALUES (@.field2, ..., @.field5)

Null Field Values not returned - For XML AUTO

Is there a way to get SQL to return NULL field values as 'empty' XML tags,
instead of completely omitting them from the output?
I'm using FOR XML AUTO
Michael L wrote:
> Is there a way to get SQL to return NULL field values as 'empty' XML tags,
> instead of completely omitting them from the output?
> I'm using FOR XML AUTO
Use
FOM XML AUTO, ELEMENTS XSINIL
that way for a null value in a column you get
<Columnname xsi:nil="true"/>
where xsi is bound to http://www.w3.org/2001/XMLSchema-instance.
See "Using the XSINIL directive" in
<http://msdn2.microsoft.com/en-us/library/ms177400.aspx>
Martin Honnen -- MVP XML
http://JavaScript.FAQTs.com/
|||THANKS! I assume this only works in SQL Server 2005?
"Martin Honnen" <mahotrash@.yahoo.de> wrote in message
news:%23PvVNP2pHHA.4772@.TK2MSFTNGP05.phx.gbl...
> Michael L wrote:
> Use
> FOM XML AUTO, ELEMENTS XSINIL
> that way for a null value in a column you get
> <Columnname xsi:nil="true"/>
> where xsi is bound to http://www.w3.org/2001/XMLSchema-instance.
> See "Using the XSINIL directive" in
> <http://msdn2.microsoft.com/en-us/library/ms177400.aspx>
> --
> Martin Honnen -- MVP XML
> http://JavaScript.FAQTs.com/
|||Correct. This is only available in 2005. In 2000 you could always use
ISNULL(col, '') in the select clause (with cast adjustments for nonstring
types).
Best regards
Michael
"Michael L" <mlarter@.comcast.net> wrote in message
news:CMGdnckxp900QfjbnZ2dnUVZ_hCdnZ2d@.comcast.com. ..
> THANKS! I assume this only works in SQL Server 2005?
>
> "Martin Honnen" <mahotrash@.yahoo.de> wrote in message
> news:%23PvVNP2pHHA.4772@.TK2MSFTNGP05.phx.gbl...
>

Null Field Values not returned - For XML AUTO

Is there a way to get SQL to return NULL field values as 'empty' XML tags,
instead of completely omitting them from the output?
I'm using FOR XML AUTOMichael L wrote:
> Is there a way to get SQL to return NULL field values as 'empty' XML tags,
> instead of completely omitting them from the output?
> I'm using FOR XML AUTO
Use
FOM XML AUTO, ELEMENTS XSINIL
that way for a null value in a column you get
<Columnname xsi:nil="true"/>
where xsi is bound to http://www.w3.org/2001/XMLSchema-instance.
See "Using the XSINIL directive" in
<http://msdn2.microsoft.com/en-us/library/ms177400.aspx>
Martin Honnen -- MVP XML
http://JavaScript.FAQTs.com/|||THANKS! I assume this only works in SQL Server 2005?
"Martin Honnen" <mahotrash@.yahoo.de> wrote in message
news:%23PvVNP2pHHA.4772@.TK2MSFTNGP05.phx.gbl...
> Michael L wrote:
> Use
> FOM XML AUTO, ELEMENTS XSINIL
> that way for a null value in a column you get
> <Columnname xsi:nil="true"/>
> where xsi is bound to http://www.w3.org/2001/XMLSchema-instance.
> See "Using the XSINIL directive" in
> <http://msdn2.microsoft.com/en-us/library/ms177400.aspx>
> --
> Martin Honnen -- MVP XML
> http://JavaScript.FAQTs.com/|||Correct. This is only available in 2005. In 2000 you could always use
ISNULL(col, '') in the select clause (with cast adjustments for nonstring
types).
Best regards
Michael
"Michael L" <mlarter@.comcast.net> wrote in message
news:CMGdnckxp900QfjbnZ2dnUVZ_hCdnZ2d@.co
mcast.com...
> THANKS! I assume this only works in SQL Server 2005?
>
> "Martin Honnen" <mahotrash@.yahoo.de> wrote in message
> news:%23PvVNP2pHHA.4772@.TK2MSFTNGP05.phx.gbl...
>