在sqlserver2008中测试null和空间 [英] testing null and space in sqlserver2008

查看:55
本文介绍了在sqlserver2008中测试null和空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的桌子上有单独的列,分别代表房屋编号,城市,州.但是我想将房屋编号,房屋,州作为地址,问题是我在这些字段中输入了空间,我得到了、、、 列表,所以我想测试空间.

Hi my table has separate columns for house no,city,state.But i want adress as houseno,city,state problem is that is i have space entered in these fields i get ,,,
list so i want to test for space.

推荐答案

您好哥们,此代码可能会有所帮助.


Hello dude may be helpful this code.


declare @house  nvarchar(200)
declare @city  nvarchar(200)
declare @state nvarchar(200)


set @house='50';
set @city='Himaat nagar';
set @state='Delhi';

select case when @house !='' then  @house else '' end  +  (case when @city !='' then case when @house!='' then ' , '+@city else @city end else ''  end)  +

 (case when @state !='' then case when @city!='' then ' , '+@state else @state end else ''end)




使用此代码,其中@house替换您的表列house,@ city替换您的表列City和@state替换您的表列状态,并添加和of的查询(来自tablename)


据我了解您的问题,这是确定适当的工作

谢谢




Use this code Where @house replace your table column house ,@city replace your table column City and @state replace your table column state and add and of query as (from tablename )


It is confirm proper work as i know your problem

Thanks


[在案例的其他部分更新了字段.如果忘记了在其他部分进行替换],请尝试此操作..

我的sql不好,但是我尝试了一下,并根据您的要求完美地运行了..

[updated the fields in else part of case..if forgot to replace in else part]try this..

I am not good in sql but I tried this and according to your requirement its perfectly working..

select case when isnull(ltrim(rtrim(houseno)),'') + ',' + isnull(ltrim(rtrim(city)),'') + ',' +  isnull(ltrim(rtrim(state)),'') =',,' then ' ' else isnull(ltrim(rtrim(houseno)),'') + ',' + isnull(ltrim(rtrim(city)),'') + ',' +  isnull(ltrim(rtrim(state)),'') end as address from [tablename] 



如果您有解决方案,请回答它.

谢谢



make it answer if you get your solution.

Thanks


[改进了我的解决方案.....]此查询可以为您提供帮助..

[Improved my solution........]May this query helps you..

select isnull(ltrim(rtrim(houseno)),'')+','+ isnull(ltrim(rtrim(city)),'') +','+ isnull(ltrim(rtrim(state)),'') as address from tablename




如果您有解决方案,请回答它.


谢谢




make it answer if you get your solution.


Thanks


这篇关于在sqlserver2008中测试null和空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆