Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 find empty strings

Author  Topic 

rjhe22
Constraint Violating Yak Guru

283 Posts

Posted - 2009-01-15 : 09:03:55
i have done this before but cant remember.

i want to TRIM the Column and compare it to '''

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-01-15 : 09:05:41
SELECT *
FROM Table1
WHERE Col1 IS NULL OR Col1 = ''



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-01-15 : 09:06:51
[code]
SELECT *
FROM Table1
WHERE Col1 > ''
[/code]
Go to Top of Page

rjhe22
Constraint Violating Yak Guru

283 Posts

Posted - 2009-01-16 : 05:27:46
hi

can anyone see whats wrong with this
select CashID ,rtrim(Notes)
from dbo.Cash_Balances


get this error
Argument data type text is invalid for argument 1 of rtrim function.
Go to Top of Page

raky
Aged Yak Warrior

767 Posts

Posted - 2009-01-16 : 05:30:32
quote:
Originally posted by rjhe22

hi

can anyone see whats wrong with this
select CashID ,rtrim(Notes)
from dbo.Cash_Balances


get this error
Argument data type text is invalid for argument 1 of rtrim function.



TRY THIS

select CashID ,rtrim(CAST (Notes AS VARCHAR(8000)))
from dbo.Cash_Balances
Go to Top of Page

rjhe22
Constraint Violating Yak Guru

283 Posts

Posted - 2009-01-16 : 05:31:43
why did u put (CAST (Notes AS VARCHAR(8000)) in
Go to Top of Page

raky
Aged Yak Warrior

767 Posts

Posted - 2009-01-16 : 05:34:13
quote:
Originally posted by rjhe22

why did u put (CAST (Notes AS VARCHAR(8000)) in



RTRIM Cannot be used with text datatype...It can be used only with varchar or nvarchar
Go to Top of Page

ashishashish
Constraint Violating Yak Guru

408 Posts

Posted - 2009-01-16 : 05:34:28
May Be Ur datatype is not of varchar,,,,
so cast use is there to convert it to varchar.....


Go to Top of Page

rjhe22
Constraint Violating Yak Guru

283 Posts

Posted - 2009-01-16 : 05:39:01
ok right i understand now thanks
Go to Top of Page

raky
Aged Yak Warrior

767 Posts

Posted - 2009-01-16 : 05:43:14
quote:
Originally posted by rjhe22

ok right i understand now thanks



welcome...
Go to Top of Page

rjhe22
Constraint Violating Yak Guru

283 Posts

Posted - 2009-01-16 : 05:56:19
thats work but it pulling all the records back.

im trying to RTRIM the Column and compare it to '''.

am i on the right track
Go to Top of Page

raky
Aged Yak Warrior

767 Posts

Posted - 2009-01-16 : 06:01:49
quote:
Originally posted by rjhe22

thats work but it pulling all the records back.

im trying to RTRIM the Column and compare it to '''.

am i on the right track



Please Post full query which u are using...where are you trying

compare it to '''
Go to Top of Page

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2009-01-16 : 06:04:41
what is the need of rtrim and comparing the values with empty string
Go to Top of Page

rjhe22
Constraint Violating Yak Guru

283 Posts

Posted - 2009-01-16 : 06:05:28
incase some of them that have notes dont have a blank space before it
Go to Top of Page

Jai Krishna
Constraint Violating Yak Guru

333 Posts

Posted - 2009-01-16 : 06:07:46
SELECT *
FROM Table1
WHERE ISNULL(LTRIM(RTRIM(Col1)),'') = ''


Jai Krishna
Go to Top of Page

raky
Aged Yak Warrior

767 Posts

Posted - 2009-01-16 : 06:09:07
I think what u need is ltrim..anyway to get correct solution please post some sample data and expected output..
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-01-16 : 07:30:11
where text_col is not null or datalength(text_col)>0

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-01-16 : 08:53:08
quote:
Originally posted by raky

quote:
Originally posted by rjhe22

why did u put (CAST (Notes AS VARCHAR(8000)) in



RTRIM Cannot be used with text datatype...It can be used only with varchar or nvarchar


what happens if Notes is a text field and has over 8000 characters? have you considered that
Go to Top of Page
   

- Advertisement -