【发布时间】:2013-04-08 18:11:33
【问题描述】:
我的查询是将 varchar 转换为字符串,
select top(5)'Insert into jobs(minexperience,maxexperience)values('+
cast(substring(Experience as varchar(50)),0,patindex('%to%',Experience))*365*24*60*60,
cast(substring(Experience as
varchar(50)),patindex('%to%',Experience)+2,patindex('%Years%',Experience)-patindex('%to%',Experience)-2)*365*24*60*60+')'
from requirementsdetailsfororganization
在下面的查询中,我有一个错误“关键字'AS'附近的语法不正确。”
我想将字符串转换为整数。
有什么帮助吗?
【问题讨论】:
-
你想将体验转换为字符串
-
你必须切换强制转换和子字符串函数。
-
使用
substring(cast(Experience as ....而不是cast(substring(Experience as.... -
在没有 ORDER BY 的情况下也是 TOP 5?所以你不在乎你得到哪个5?为什么要存储像
1997 to 2005这样的不可靠字符串来表示体验持续时间?为什么不将 1997 和 2005 存储在不同的列中? -
我试过切换。但同样的错误。我从旧数据库中获取值并执行我的新数据库。像这样创建的旧数据库。
标签: sql-server casting substring patindex