字符串问题

SuperZhou 2002-04-20 06:23:39
select convert(char(10),passedtime,102),convert(char(8),passedtime,108)
,tollcenterno,tollgateno,roadwayno,
left(cardno, 5),right(cardno, 10),cartype,
charge,carno,
case cardstatus
when '01' then '非法'
when '02' then '正常'
when '03' then '挂失'
when '04' then '临界'
when '05' then '透支'
when '06' then '销卡'
when '07' then '免费'
when '08' then '无卡'
when '09' then '月卡'
when '10' then '优惠'
end
from PassedCars
where passedtime between @startdatetime and @enddatetime
怎样将上面的语句赋值给varchar型字符串(要保留Select语句中的单引号)?

...全文
41 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
SuperZhou 2002-04-21
  • 打赏
  • 举报
回复
to rwq_(风云浪子),谢了!
rwq_ 2002-04-21
  • 打赏
  • 举报
回复
set @sqlcmd='select convert(char(10),passedtime,102),convert(char(8),passedtime,108)
,tollcenterno,tollgateno,roadwayno,
left(cardno, 5),right(cardno, 10),cartype,
charge,carno,
case cardstatus
when ''01'' then ''非法''
when ''02'' then ''正常''
when ''03'' then ''挂失''
when ''04'' then ''临界''
when ''05'' then ''透支''
when ''06'' then ''销卡''
when ''07'' then ''免费''
when ''08'' then ''无卡''
when ''09'' then ''月卡''
when ''10'' then ''优惠''
end
from PassedCars
where passedtime between'''+ @startdatetime +''' and '''+@enddatetime+''''

上面的@startdatetime 我不知道你的格式!


我给你一个特殊的例子:
declare @sqlcmd varchar(1000)
set @sqlcmd='select convert(char(10),passedtime,102),convert(char(8),passedtime,108)
,tollcenterno,tollgateno,roadwayno,
left(cardno, 5),right(cardno, 10),cartype,
charge,carno,
case cardstatus
when ''01'' then ''非法''
when ''02'' then ''正常''
when ''03'' then ''挂失''
when ''04'' then ''临界''
when ''05'' then ''透支''
when ''06'' then ''销卡''
when ''07'' then ''免费''
when ''08'' then ''无卡''
when ''09'' then ''月卡''
when ''10'' then ''优惠''
end
from PassedCars
where passedtime between convert(datetime,'''+ convert(varchar(100),getdate()) +''') and convert(datetime,'''+convert(varchar(100),getdate())+''')'
print @sqlcmd
SuperZhou 2002-04-20
  • 打赏
  • 举报
回复
试过了,不行
xmsailor 2002-04-20
  • 打赏
  • 举报
回复
使用两个单引号试一下,如下

select convert(char(10),passedtime,102),convert(char(8),passedtime,108)
,tollcenterno,tollgateno,roadwayno,
left(cardno, 5),right(cardno, 10),cartype,
charge,carno,
case cardstatus
when ''01'' then ''非法''
when ''02'' then ''正常''
when ''03'' then ''挂失''
when '04' then ''临界''
when ''05'' then ''透支''
when ''06'' then ''销卡''
when ''07'' then ''免费''
when ''08'' then ''无卡''
when ''09'' then ''月卡''
when ''10'' then ''优惠''
end
from PassedCars
where passedtime between @startdatetime and @enddatetime
jaguarcts 2002-04-20
  • 打赏
  • 举报
回复
动态SQL呀。

34,575

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧