Sunday, February 19, 2012

Allow zero length strings

In Microsoft Access there is the option to set a field to accept zero length
strings.
This of course means that an empty text box could be entered into the
database without an error occuring.
Is there any way I can do this in SQL Server.
I know that when developing a front end I could write some code to check
each text box and when a textbox is empty, push a " " into it before
insertion but I'm sick of this.
Is there any other way ?We use a Default in SQL Server 2000 like the following:
if exists (select * from dbo.sysobjects where id =object_id(N'[dbo].[EmptyString]') and OBJECTPROPERTY(id,
N'IsDefault') = 1)
drop default [dbo].[EmptyString]
GO
create default [Space] as ''
GO
>--Original Message--
>In Microsoft Access there is the option to set a field to
accept zero length
>strings.
>This of course means that an empty text box could be
entered into the
>database without an error occuring.
>Is there any way I can do this in SQL Server.
>I know that when developing a front end I could write
some code to check
>each text box and when a textbox is empty, push a " "
into it before
>insertion but I'm sick of this.
>Is there any other way ?
>
>.
>|||You can insert an empty (zero-length) string into a varchar (or nvarchar)
column:
CREATE TABLE MyTable
(
MyColumn varchar(10) NOT NULL
)
INSERT INTO MyTable VALUES('')
SELECT
MyColumn,
DATALENGTH(MyColumn)
FROM MyTable
GO
I don't know much about Access programming so there may be programming
considerations. Does an empty text box return in a zero-length string value
or does this return a NULL value?
--
Hope this helps.
Dan Guzman
SQL Server MVP
"Poppy" <paul.diamond@.NOSPAMthemedialounge.com> wrote in message
news:ePYQ%23tctDHA.980@.TK2MSFTNGP10.phx.gbl...
> In Microsoft Access there is the option to set a field to accept zero
length
> strings.
> This of course means that an empty text box could be entered into the
> database without an error occuring.
> Is there any way I can do this in SQL Server.
> I know that when developing a front end I could write some code to check
> each text box and when a textbox is empty, push a " " into it before
> insertion but I'm sick of this.
> Is there any other way ?
>

No comments:

Post a Comment