Showing posts with label strings. Show all posts
Showing posts with label strings. Show all posts

Monday, March 12, 2012

Nulls Versus Blanks PArt 2

How do I configure SQL 2000 to insert <NULLS> when deleting an entry and not
emty strings. On the same Token the server should insert <NULLS> by default
My server was configured like that and for some reason now it is behaving
differently. There has to be some global configuration, I am not looking for
individual constraints and default values. If there is no global
configuration am I looking at some kind of bug?
Thanks
IT PHYTOSAN>>How do I configure SQL 2000 to insert <NULLS> when deleting an entry
I assume by deleting you don't mean deleting the whole row like this
DELETE table where SomeColumn =SomeValue
Are you talking about EM (Enterprise Manager) ?
If so then enter CTRL + 0 in the column and a NULL will be inserted
Denis the SQL Menace
http://sqlservercode.blogspot.com/|||> How do I configure SQL 2000 to insert <NULLS> when deleting an entry and notn">
> emty strings.
There's no such setting as this never happens. Let me explain:
If you by "deleting an entry" mean deleting a row, using the DELETE SQL comm
and, then the row is
gone and there is no place for NULL nor space.
If you mean changing the value of a column for a row, then you set this usin
g the UPDATE statement:
UPDATE tblname
SET colname = NULL
WHERE ...
So you need to dig in the application to see how it modifies the data.
Possibly you has a default constraint for a column, with NULL and that defau
lt is not an empty
string. You can refer to a default for a column in an update like:
UPDATE tblname
SET colname = DEFAULT
WHERE ...
See if you do have any default for this column using sp_help.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"IT PHYTOSAN" <ITPHYTOSAN@.discussions.microsoft.com> wrote in message
news:FD708941-A75E-4C00-8D3F-706FFD2E7744@.microsoft.com...
> How do I configure SQL 2000 to insert <NULLS> when deleting an entry and n
ot
> emty strings. On the same Token the server should insert <NULLS> by defaul
t
> My server was configured like that and for some reason now it is behaving
> differently. There has to be some global configuration, I am not looking f
or
> individual constraints and default values. If there is no global
> configuration am I looking at some kind of bug?
> Thanks
> IT PHYTOSAN|||Thanks for your help. Looking at the source of the issue, what I would reall
y
like to accomplish is that varchar and char entries treat empty strings as
<NULL>'s. When deleting a single field (using the delete button on the
keyboard in a table opended enterprise manager for example) I would like to
see a <NULL> inserted rather than an empty string. There must be a simple wa
y
of enforcing meaningfull entries in the tables.
any hints?
IT PHYTOSAN
"Tibor Karaszi" wrote:

> There's no such setting as this never happens. Let me explain:
> If you by "deleting an entry" mean deleting a row, using the DELETE SQL co
mmand, then the row is
> gone and there is no place for NULL nor space.
> If you mean changing the value of a column for a row, then you set this us
ing the UPDATE statement:
> UPDATE tblname
> SET colname = NULL
> WHERE ...
> So you need to dig in the application to see how it modifies the data.
> Possibly you has a default constraint for a column, with NULL and that def
ault is not an empty
> string. You can refer to a default for a column in an update like:
> UPDATE tblname
> SET colname = DEFAULT
> WHERE ...
> See if you do have any default for this column using sp_help.
>
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://www.solidqualitylearning.com/
>
> "IT PHYTOSAN" <ITPHYTOSAN@.discussions.microsoft.com> wrote in message
> news:FD708941-A75E-4C00-8D3F-706FFD2E7744@.microsoft.com...
>|||To create NULL values from Enterprise Manager use CTRL + 0 instead of
delete
Hightlight all the text and then press CTRL + 0
Or switch to Query analyzer and write UPDATE statements like Tibor
showed you that will also give you more control and you will know
what's going on
Denis the SQL Menace
http://sqlservercode.blogspot.com/|||I am aware of CTRL + 0 but it does not fix my problem. Right now my client
(InfoPath) will insert empty strings in tables that have no entry and does
not recognize that this field is required but empty. I would like SQL server
to treat empty strings like <NULLS> as mentioned.
Thanks
IT PHYTOSAN
"SQL" wrote:

> To create NULL values from Enterprise Manager use CTRL + 0 instead of
> delete
> Hightlight all the text and then press CTRL + 0
> Or switch to Query analyzer and write UPDATE statements like Tibor
> showed you that will also give you more control and you will know
> what's going on
>
> Denis the SQL Menace
> http://sqlservercode.blogspot.com/
>|||create a trigger on the table|||that won't be recognized by InfoPath as required field. The trigger will
throw an error but for me that's after the fact.
Thanks
IT PHYTOSAN
"SQL" wrote:

> create a trigger on the table
>|||As suggested, this is an application (InfoPath) problem.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"IT PHYTOSAN" <ITPHYTOSAN@.discussions.microsoft.com> wrote in message
news:0AF6F82F-CC92-4F15-A988-779391530969@.microsoft.com...[vbcol=seagreen]
>I am aware of CTRL + 0 but it does not fix my problem. Right now my client
> (InfoPath) will insert empty strings in tables that have no entry and does
> not recognize that this field is required but empty. I would like SQL serv
er
> to treat empty strings like <NULLS> as mentioned.
> Thanks
> IT PHYTOSAN
> "SQL" wrote:
>|||Wow I am really stuck now, they can't help me over there either. Any clues?
Thanks anyway
IT PHYTOSAN
"Tibor Karaszi" wrote:

> As suggested, this is an application (InfoPath) problem.
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://www.solidqualitylearning.com/
>
> "IT PHYTOSAN" <ITPHYTOSAN@.discussions.microsoft.com> wrote in message
> news:0AF6F82F-CC92-4F15-A988-779391530969@.microsoft.com...
>

Nulls Versus Blanks PArt 2

How do I configure SQL 2000 to insert <NULLS> when deleting an entry and not
emty strings. On the same Token the server should insert <NULLS> by default
My server was configured like that and for some reason now it is behaving
differently. There has to be some global configuration, I am not looking for
individual constraints and default values. If there is no global
configuration am I looking at some kind of bug?
Thanks
IT PHYTOSAN>>How do I configure SQL 2000 to insert <NULLS> when deleting an entry
I assume by deleting you don't mean deleting the whole row like this
DELETE table where SomeColumn =SomeValue
Are you talking about EM (Enterprise Manager) ?
If so then enter CTRL + 0 in the column and a NULL will be inserted
Denis the SQL Menace
http://sqlservercode.blogspot.com/|||> How do I configure SQL 2000 to insert <NULLS> when deleting an entry and not
> emty strings.
There's no such setting as this never happens. Let me explain:
If you by "deleting an entry" mean deleting a row, using the DELETE SQL command, then the row is
gone and there is no place for NULL nor space.
If you mean changing the value of a column for a row, then you set this using the UPDATE statement:
UPDATE tblname
SET colname = NULL
WHERE ...
So you need to dig in the application to see how it modifies the data.
Possibly you has a default constraint for a column, with NULL and that default is not an empty
string. You can refer to a default for a column in an update like:
UPDATE tblname
SET colname = DEFAULT
WHERE ...
See if you do have any default for this column using sp_help.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"IT PHYTOSAN" <ITPHYTOSAN@.discussions.microsoft.com> wrote in message
news:FD708941-A75E-4C00-8D3F-706FFD2E7744@.microsoft.com...
> How do I configure SQL 2000 to insert <NULLS> when deleting an entry and not
> emty strings. On the same Token the server should insert <NULLS> by default
> My server was configured like that and for some reason now it is behaving
> differently. There has to be some global configuration, I am not looking for
> individual constraints and default values. If there is no global
> configuration am I looking at some kind of bug?
> Thanks
> IT PHYTOSAN|||Thanks for your help. Looking at the source of the issue, what I would really
like to accomplish is that varchar and char entries treat empty strings as
<NULL>'s. When deleting a single field (using the delete button on the
keyboard in a table opended enterprise manager for example) I would like to
see a <NULL> inserted rather than an empty string. There must be a simple way
of enforcing meaningfull entries in the tables.
any hints?
IT PHYTOSAN
"Tibor Karaszi" wrote:
> > How do I configure SQL 2000 to insert <NULLS> when deleting an entry and not
> > emty strings.
> There's no such setting as this never happens. Let me explain:
> If you by "deleting an entry" mean deleting a row, using the DELETE SQL command, then the row is
> gone and there is no place for NULL nor space.
> If you mean changing the value of a column for a row, then you set this using the UPDATE statement:
> UPDATE tblname
> SET colname = NULL
> WHERE ...
> So you need to dig in the application to see how it modifies the data.
> Possibly you has a default constraint for a column, with NULL and that default is not an empty
> string. You can refer to a default for a column in an update like:
> UPDATE tblname
> SET colname = DEFAULT
> WHERE ...
> See if you do have any default for this column using sp_help.
>
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://www.solidqualitylearning.com/
>
> "IT PHYTOSAN" <ITPHYTOSAN@.discussions.microsoft.com> wrote in message
> news:FD708941-A75E-4C00-8D3F-706FFD2E7744@.microsoft.com...
> > How do I configure SQL 2000 to insert <NULLS> when deleting an entry and not
> > emty strings. On the same Token the server should insert <NULLS> by default
> > My server was configured like that and for some reason now it is behaving
> > differently. There has to be some global configuration, I am not looking for
> > individual constraints and default values. If there is no global
> > configuration am I looking at some kind of bug?
> >
> > Thanks
> >
> > IT PHYTOSAN
>|||To create NULL values from Enterprise Manager use CTRL + 0 instead of
delete
Hightlight all the text and then press CTRL + 0
Or switch to Query analyzer and write UPDATE statements like Tibor
showed you that will also give you more control and you will know
what's going on
Denis the SQL Menace
http://sqlservercode.blogspot.com/|||I am aware of CTRL + 0 but it does not fix my problem. Right now my client
(InfoPath) will insert empty strings in tables that have no entry and does
not recognize that this field is required but empty. I would like SQL server
to treat empty strings like <NULLS> as mentioned.
Thanks
IT PHYTOSAN
"SQL" wrote:
> To create NULL values from Enterprise Manager use CTRL + 0 instead of
> delete
> Hightlight all the text and then press CTRL + 0
> Or switch to Query analyzer and write UPDATE statements like Tibor
> showed you that will also give you more control and you will know
> what's going on
>
> Denis the SQL Menace
> http://sqlservercode.blogspot.com/
>|||create a trigger on the table|||that won't be recognized by InfoPath as required field. The trigger will
throw an error but for me that's after the fact.
Thanks
IT PHYTOSAN
"SQL" wrote:
> create a trigger on the table
>|||As suggested, this is an application (InfoPath) problem.
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"IT PHYTOSAN" <ITPHYTOSAN@.discussions.microsoft.com> wrote in message
news:0AF6F82F-CC92-4F15-A988-779391530969@.microsoft.com...
>I am aware of CTRL + 0 but it does not fix my problem. Right now my client
> (InfoPath) will insert empty strings in tables that have no entry and does
> not recognize that this field is required but empty. I would like SQL server
> to treat empty strings like <NULLS> as mentioned.
> Thanks
> IT PHYTOSAN
> "SQL" wrote:
>> To create NULL values from Enterprise Manager use CTRL + 0 instead of
>> delete
>> Hightlight all the text and then press CTRL + 0
>> Or switch to Query analyzer and write UPDATE statements like Tibor
>> showed you that will also give you more control and you will know
>> what's going on
>>
>> Denis the SQL Menace
>> http://sqlservercode.blogspot.com/
>>|||Wow I am really stuck now, they can't help me over there either. Any clues?
Thanks anyway
IT PHYTOSAN
"Tibor Karaszi" wrote:
> As suggested, this is an application (InfoPath) problem.
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://www.solidqualitylearning.com/
>
> "IT PHYTOSAN" <ITPHYTOSAN@.discussions.microsoft.com> wrote in message
> news:0AF6F82F-CC92-4F15-A988-779391530969@.microsoft.com...
> >I am aware of CTRL + 0 but it does not fix my problem. Right now my client
> > (InfoPath) will insert empty strings in tables that have no entry and does
> > not recognize that this field is required but empty. I would like SQL server
> > to treat empty strings like <NULLS> as mentioned.
> >
> > Thanks
> >
> > IT PHYTOSAN
> >
> > "SQL" wrote:
> >
> >> To create NULL values from Enterprise Manager use CTRL + 0 instead of
> >> delete
> >> Hightlight all the text and then press CTRL + 0
> >> Or switch to Query analyzer and write UPDATE statements like Tibor
> >> showed you that will also give you more control and you will know
> >> what's going on
> >>
> >>
> >> Denis the SQL Menace
> >> http://sqlservercode.blogspot.com/
> >>
> >>
>|||You may use a INSTEAD OF type of trigger to do your data validation.
"IT PHYTOSAN" <ITPHYTOSAN@.discussions.microsoft.com> wrote in message
news:E1BDC16A-E880-4919-95CE-FCEA4DE3EC7C@.microsoft.com...
> that won't be recognized by InfoPath as required field. The trigger will
> throw an error but for me that's after the fact.
> Thanks
> IT PHYTOSAN
> "SQL" wrote:
>> create a trigger on the table
>>|||I suggest you open a case with MS Support. If you don't know what caused the change, or even if the
change was at the database level, it is hard to suggest anything. If the change was at the database
level, and you don't know who did it any what they did and don't know what the database definition
is supposed to look like, it is hard to tell anything. MS Support should be able to track this down
for you.
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"IT PHYTOSAN" <ITPHYTOSAN@.discussions.microsoft.com> wrote in message
news:3D54C44E-093D-4A78-997F-7E49AECB4D12@.microsoft.com...
> Wow I am really stuck now, they can't help me over there either. Any clues?
> Thanks anyway
> IT PHYTOSAN
> "Tibor Karaszi" wrote:
>> As suggested, this is an application (InfoPath) problem.
>> --
>> Tibor Karaszi, SQL Server MVP
>> http://www.karaszi.com/sqlserver/default.asp
>> http://www.solidqualitylearning.com/
>>
>> "IT PHYTOSAN" <ITPHYTOSAN@.discussions.microsoft.com> wrote in message
>> news:0AF6F82F-CC92-4F15-A988-779391530969@.microsoft.com...
>> >I am aware of CTRL + 0 but it does not fix my problem. Right now my client
>> > (InfoPath) will insert empty strings in tables that have no entry and does
>> > not recognize that this field is required but empty. I would like SQL server
>> > to treat empty strings like <NULLS> as mentioned.
>> >
>> > Thanks
>> >
>> > IT PHYTOSAN
>> >
>> > "SQL" wrote:
>> >
>> >> To create NULL values from Enterprise Manager use CTRL + 0 instead of
>> >> delete
>> >> Hightlight all the text and then press CTRL + 0
>> >> Or switch to Query analyzer and write UPDATE statements like Tibor
>> >> showed you that will also give you more control and you will know
>> >> what's going on
>> >>
>> >>
>> >> Denis the SQL Menace
>> >> http://sqlservercode.blogspot.com/
>> >>
>> >>
>>|||That is good adivce. I'll do that and post back if the solution can be found.
Thans again for your help to both of you.
IT PHYTOSAN
"Tibor Karaszi" wrote:
> I suggest you open a case with MS Support. If you don't know what caused the change, or even if the
> change was at the database level, it is hard to suggest anything. If the change was at the database
> level, and you don't know who did it any what they did and don't know what the database definition
> is supposed to look like, it is hard to tell anything. MS Support should be able to track this down
> for you.
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://www.solidqualitylearning.com/
>
> "IT PHYTOSAN" <ITPHYTOSAN@.discussions.microsoft.com> wrote in message
> news:3D54C44E-093D-4A78-997F-7E49AECB4D12@.microsoft.com...
> > Wow I am really stuck now, they can't help me over there either. Any clues?
> >
> > Thanks anyway
> >
> > IT PHYTOSAN
> >
> > "Tibor Karaszi" wrote:
> >
> >> As suggested, this is an application (InfoPath) problem.
> >>
> >> --
> >> Tibor Karaszi, SQL Server MVP
> >> http://www.karaszi.com/sqlserver/default.asp
> >> http://www.solidqualitylearning.com/
> >>
> >>
> >> "IT PHYTOSAN" <ITPHYTOSAN@.discussions.microsoft.com> wrote in message
> >> news:0AF6F82F-CC92-4F15-A988-779391530969@.microsoft.com...
> >> >I am aware of CTRL + 0 but it does not fix my problem. Right now my client
> >> > (InfoPath) will insert empty strings in tables that have no entry and does
> >> > not recognize that this field is required but empty. I would like SQL server
> >> > to treat empty strings like <NULLS> as mentioned.
> >> >
> >> > Thanks
> >> >
> >> > IT PHYTOSAN
> >> >
> >> > "SQL" wrote:
> >> >
> >> >> To create NULL values from Enterprise Manager use CTRL + 0 instead of
> >> >> delete
> >> >> Hightlight all the text and then press CTRL + 0
> >> >> Or switch to Query analyzer and write UPDATE statements like Tibor
> >> >> showed you that will also give you more control and you will know
> >> >> what's going on
> >> >>
> >> >>
> >> >> Denis the SQL Menace
> >> >> http://sqlservercode.blogspot.com/
> >> >>
> >> >>
> >>
> >>
>

Nulls in the middle of strings

How can I check for Null characters (CHAR(0) ) in the middle of a string?
CHARINDEX doesn't seem to work for it.
Also, can anyone explain why the display of the @.test_string variable is
different in the first and second SELECTs?
Thanks
Damien
DECLARE @.test_string VARCHAR( 25 )
SET @.test_string = 'test' + CHAR(0) + 'test'
SELECT @.test_string
SELECT @.test_string, ASCII( SUBSTRING( @.test_string, 5, 1 ) ), CHARINDEX(
CHAR(0), @.test_string )NULL int he middle of the string ? That sound like "nowhere in the middle of
somewhere" ;-) . AFAIK you can store either NULL or any Values in a column
but not both because NULL means nothing.
Definition: The NULL SQL keyword is used to represent either a missing value
or a value that is not applicable in a relational table.
HTH, Jens Suessmeyer.
http://www.sqlserver2005.de
--
"Damien" wrote:

> How can I check for Null characters (CHAR(0) ) in the middle of a string?
> CHARINDEX doesn't seem to work for it.
> Also, can anyone explain why the display of the @.test_string variable is
> different in the first and second SELECTs?
> Thanks
>
> Damien
>
> DECLARE @.test_string VARCHAR( 25 )
> SET @.test_string = 'test' + CHAR(0) + 'test'
> SELECT @.test_string
> SELECT @.test_string, ASCII( SUBSTRING( @.test_string, 5, 1 ) ), CHARINDEX(
> CHAR(0), @.test_string )|||Damien
I think you need SPACE(1) rather than CHAR(0)
DECLARE @.test_string VARCHAR(25)
SET @.test_string = 'test' +SPACE(1)+ 'test'
SELECT @.test_string
SELECT @.test_string,CHARINDEX(SPACE(1),@.test_st
ring)
"Damien" <Damien@.discussions.microsoft.com> wrote in message
news:658975D1-6D51-4A87-AB60-5FDDC637FA78@.microsoft.com...
> How can I check for Null characters (CHAR(0) ) in the middle of a string?
> CHARINDEX doesn't seem to work for it.
> Also, can anyone explain why the display of the @.test_string variable is
> different in the first and second SELECTs?
> Thanks
>
> Damien
>
> DECLARE @.test_string VARCHAR( 25 )
> SET @.test_string = 'test' + CHAR(0) + 'test'
> SELECT @.test_string
> SELECT @.test_string, ASCII( SUBSTRING( @.test_string, 5, 1 ) ), CHARINDEX(
> CHAR(0), @.test_string )|||-- Sorry guys, I don't think you understand me. Null characters can live in
the middle of strings, I just want to know how to check for them without
looping through every character in the column.
-- I have a string in a CHAR(10) field, it looks like this: 'ADV '
-- When I run the following code on it, I get this:
-- pos char ascii_code
-- 1 A 65
-- 2 D 68
-- 3 V 86
-- 4 0
-- 5 0
-- 6 0
-- 7 0
-- 8 0
-- 9 0
-- And not what I would expect, which is this:
--
-- pos char ascii_code
-- 1 A 65
-- 2 D 68
-- 3 V 86
-- 4 32
-- 5 32
-- 6 32
-- 7 32
-- 8 32
-- 9 32
SET NOCOUNT ON
DECLARE @.pos INT
DECLARE @.test_string CHAR( 10 )
SET @.pos = 1
SET @.test_string = 'ADV' + REPLICATE( CHAR(0), 7 )
--SELECT @.test_string = advanced_arrears FROM jlt.pp_additional_information
WHERE client_id = 86840
WHILE @.pos < DATALENGTH( @.test_string )
BEGIN
SELECT @.pos, SUBSTRING( @.test_string, @.pos, 1 ), ASCII( SUBSTRING(
@.test_string, @.pos, 1 ) )
SET @.pos = @.pos + 1
END
SET NOCOUNT OFF
"Uri Dimant" wrote:

> Damien
> I think you need SPACE(1) rather than CHAR(0)
> DECLARE @.test_string VARCHAR(25)
> SET @.test_string = 'test' +SPACE(1)+ 'test'
> SELECT @.test_string
> SELECT @.test_string,CHARINDEX(SPACE(1),@.test_st
ring)
>
>
> "Damien" <Damien@.discussions.microsoft.com> wrote in message
> news:658975D1-6D51-4A87-AB60-5FDDC637FA78@.microsoft.com...
>
>|||Damien
CREATE TABLE #Test
(
col CHAR(10)
)
INSERT INTO #Test VALUES ('ADV')
SELECT col,len(col),datalength(col)
FROM #Test
--Based on BOL's example
DECLARE @.position int, @.string char(8)
SET @.position = 1
SELECT @.string=col FROM #Test --Only for testing
WHILE @.position <= DATALENGTH(@.string)
BEGIN
SELECT LTRIM(RTRIM(CHAR(ASCII(SUBSTRING(@.string
, @.position, 1))))),
LTRIM(RTRIM(ASCII(SUBSTRING(@.string, @.position, 1))))
SET @.position = @.position + 1
END
"Damien" <Damien@.discussions.microsoft.com> wrote in message
news:3557ECBF-3C03-4A6C-BE7A-DE5960AF7A6D@.microsoft.com...
> -- Sorry guys, I don't think you understand me. Null characters can live
in
> the middle of strings, I just want to know how to check for them without
> looping through every character in the column.
> -- I have a string in a CHAR(10) field, it looks like this: 'ADV '
> -- When I run the following code on it, I get this:
> -- pos char ascii_code
> -- 1 A 65
> -- 2 D 68
> -- 3 V 86
> -- 4 0
> -- 5 0
> -- 6 0
> -- 7 0
> -- 8 0
> -- 9 0
> -- And not what I would expect, which is this:
> --
> -- pos char ascii_code
> -- 1 A 65
> -- 2 D 68
> -- 3 V 86
> -- 4 32
> -- 5 32
> -- 6 32
> -- 7 32
> -- 8 32
> -- 9 32
>
> SET NOCOUNT ON
> DECLARE @.pos INT
> DECLARE @.test_string CHAR( 10 )
> SET @.pos = 1
> SET @.test_string = 'ADV' + REPLICATE( CHAR(0), 7 )
> --SELECT @.test_string = advanced_arrears FROM
jlt. pp_additional_information
> WHERE client_id = 86840
>
> WHILE @.pos < DATALENGTH( @.test_string )
> BEGIN
> SELECT @.pos, SUBSTRING( @.test_string, @.pos, 1 ), ASCII( SUBSTRING(
> @.test_string, @.pos, 1 ) )
> SET @.pos = @.pos + 1
> END
>
> SET NOCOUNT OFF
>
> "Uri Dimant" wrote:
>
string?
is
CHARINDEX(|||I think you have a tough time ahead of you. The string datatypes are designe
d to handle printable
characters, not control characters. The nul character causes all kinds of pr
oblems. Perhaps because
SQL Server is written in C++, and nul terminates a string in C++? I don't kn
ow, hard to speculate.
Anyhow, you are using the product in a way it isn't intended to be used. You
r best bet is to get rid
of the nul characters (seems like REPLACE isn't an option for this...).
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"Damien" <Damien@.discussions.microsoft.com> wrote in message
news:3557ECBF-3C03-4A6C-BE7A-DE5960AF7A6D@.microsoft.com...
> -- Sorry guys, I don't think you understand me. Null characters can live
in
> the middle of strings, I just want to know how to check for them without
> looping through every character in the column.
> -- I have a string in a CHAR(10) field, it looks like this: 'ADV '
> -- When I run the following code on it, I get this:
> -- pos char ascii_code
> -- 1 A 65
> -- 2 D 68
> -- 3 V 86
> -- 4 0
> -- 5 0
> -- 6 0
> -- 7 0
> -- 8 0
> -- 9 0
> -- And not what I would expect, which is this:
> --
> -- pos char ascii_code
> -- 1 A 65
> -- 2 D 68
> -- 3 V 86
> -- 4 32
> -- 5 32
> -- 6 32
> -- 7 32
> -- 8 32
> -- 9 32
>
> SET NOCOUNT ON
> DECLARE @.pos INT
> DECLARE @.test_string CHAR( 10 )
> SET @.pos = 1
> SET @.test_string = 'ADV' + REPLICATE( CHAR(0), 7 )
> --SELECT @.test_string = advanced_arrears FROM jlt.pp_additional_informatio
n
> WHERE client_id = 86840
>
> WHILE @.pos < DATALENGTH( @.test_string )
> BEGIN
> SELECT @.pos, SUBSTRING( @.test_string, @.pos, 1 ), ASCII( SUBSTRING(
> @.test_string, @.pos, 1 ) )
> SET @.pos = @.pos + 1
> END
>
> SET NOCOUNT OFF
>
> "Uri Dimant" wrote:
>|||The @.test_string is just example for this post. The string in question is i
n
an extract from a Mainframe system. It's a fixed width file, and most of th
e
data is padded with spaces as expected. However, a few of the records are
padded with these CHAR(0) characters, and it's causing a minor problem once
imported.
Any suggestions for finding them when they are embedded within another strin
g?
Thanks
"Tibor Karaszi" wrote:

> I think you have a tough time ahead of you. The string datatypes are desig
ned to handle printable
> characters, not control characters. The nul character causes all kinds of
problems. Perhaps because
> SQL Server is written in C++, and nul terminates a string in C++? I don't
know, hard to speculate.
> Anyhow, you are using the product in a way it isn't intended to be used. Y
our best bet is to get rid
> of the nul characters (seems like REPLACE isn't an option for this...).
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://www.solidqualitylearning.com/
>
> "Damien" <Damien@.discussions.microsoft.com> wrote in message
> news:3557ECBF-3C03-4A6C-BE7A-DE5960AF7A6D@.microsoft.com...
>
>|||Damien, two possible avenues t oinvestigate...
1. Writing a stream filter in your dataaccess laye code, to replace the
char(0)s with some other special character that SQL can handle, BEFIRE
storing the strings in the database, And then another one in the DAL on the
way out to reverse the process (if it's necessary)
2. Redesign your table design so that the data for this field is in a
separate table, Assuming that the current Table this column is in is called
MyTable, and has a integer PKColumn,
Create Table TextValues
(PKColumn integer Not Null,
Sequence SmallInt Not Null,
Value VarChar(7000),
Primary Key (PKColumn , Sequence))
And store the "pieces" of the original string values in this table, without
the char(0)s... one chunk per row, with sequentially increasing sequence
numbers...
"Damien" wrote:
> The @.test_string is just example for this post. The string in question is
in
> an extract from a Mainframe system. It's a fixed width file, and most of
the
> data is padded with spaces as expected. However, a few of the records are
> padded with these CHAR(0) characters, and it's causing a minor problem onc
e
> imported.
> Any suggestions for finding them when they are embedded within another str
ing?
> Thanks
>
>
> "Tibor Karaszi" wrote:
>|||Damien,
I agree that you're not being understood here,
but it is not hard to do what you need.
Convert the string to varbinary and use substring to look
at one character at a time A table of integers to hold all the
string positions will help:
-- Permanent table of integers
create table N8000 (
pos int not null primary key
)
insert into N8000
select 1 + (OrderID-10248) + 830*(ProductID-1)
from Northwind..Orders, Northwind..Products
where ProductID < 12
and (OrderID-10248) + 830*(ProductID-1) < 8000
go
-- sample data
create table S (
pk int primary key,
s varchar(8000)
)
insert into S values
(1,cast(0x48656C6C6F00576F726C64 as varchar(8000)))
insert into S values
(2,cast(0x00000048656C6C6F00000000200020
00 as varchar(8000)))
select pk, pos from N8000, S
where substring(cast(S.s as varbinary(8000)),pos,1) = 0x00
and pos <= datalength(S.s)
-- use datalength so trailing 0x00 bytes are found
go
drop table N8000, S
Damien wrote:

>How can I check for Null characters (CHAR(0) ) in the middle of a string?
>CHARINDEX doesn't seem to work for it.
>Also, can anyone explain why the display of the @.test_string variable is
>different in the first and second SELECTs?
>Thanks
>
>Damien
>
>DECLARE @.test_string VARCHAR( 25 )
>SET @.test_string = 'test' + CHAR(0) + 'test'
>SELECT @.test_string
>SELECT @.test_string, ASCII( SUBSTRING( @.test_string, 5, 1 ) ), CHARINDEX(
>CHAR(0), @.test_string )
>|||FYI your example works as expected in yukon beta 2
"Damien" wrote:

> How can I check for Null characters (CHAR(0) ) in the middle of a string?
> CHARINDEX doesn't seem to work for it.
> Also, can anyone explain why the display of the @.test_string variable is
> different in the first and second SELECTs?
> Thanks
>
> Damien
>
> DECLARE @.test_string VARCHAR( 25 )
> SET @.test_string = 'test' + CHAR(0) + 'test'
> SELECT @.test_string
> SELECT @.test_string, ASCII( SUBSTRING( @.test_string, 5, 1 ) ), CHARINDEX(
> CHAR(0), @.test_string )

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
>