August 11, 2006 at 10:00 pm
what's the syntax for checking for empty string in a SQL statement?
Len(VarcharCol)>1
gave an error
THanks,
Sam
August 13, 2006 at 1:21 pm
It is the correct syntax. I think it is something else that is wrong.
In what context are you using LEN(VarCarCol) > 1?
N 56°04'39.16"
E 12°55'05.25"
August 14, 2006 at 8:57 am
if VarCarCol is null, you wouldnt't get an error when comparing null > 1 in SQL server; but in another application or programming language you would:
in my sample table REFERENCENBR is null in all situations:
select top 5 len(REFERENCENBR) from gmacidis where len(REFERENCENBR) > 1
results: no data and message (0 row(s) affected)
in VB however LEN(anything that evaulates asnull) > 1 raises an error;
to fix it in the SQL, you could use LEN(ISNULL(VarCarCol,''))
in a programming language, you might use a function like this:
LEN(tnull(VarCarCol)) > 1?
Public Function tnull(s as Variant) As String
If IsNull(s) Then
tnull = ""
Else
tnull = s
End If
End Function
Lowell
August 15, 2006 at 3:39 am
The column is actually text rather than varchar. Here is my statement:
Insert into dbo.CodeText(CodeID, Text1) (select CodeId, LongDescription from
CodeLookup WHERE LongDescription IS NOT NULL AND Len(LongDescription)>1)
and here is the error message:
Argument data type text is invalid for argument 1 of len function.
THanks,
Sam
August 15, 2006 at 3:45 am
Thats the problem then, as the error message says the len function cannot be use on the data type text.
What you can do is to cast the text to a varchar field to allow the use of len
i.e. Len(cast(LongDescription as varchar(4000))) >1
August 15, 2006 at 6:48 am
Thanks Bill, Lowell and Peter.
August 16, 2006 at 1:16 am
or you can use the datalength function, which can be used on text fields
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
August 16, 2006 at 6:58 am
Thanks, Gila, that helped.
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply