SQL取值问题 - MS-SQL Server / 基础类
表table
A B
12*2+10*5
4*3+10*4
15*2+81*4
如何取B列中第一个*号前的数,并赋给A列
--search
SQL code:
select left(b,charindex('*',b)-1) from table where left(b,charindex('*',b)-1)
--update
SQL code:
update table
set a = left(b,charindex('*',b)-1) from table where left(b,charindex('*',b)-1)
select left(b,charindex('*',b)-1) from table where left(b,charindex('*',b)-1) > 0
update table set a = left(b,charindex('*',b)-1) from table where left(b,charindex('*',b)-1) > 0
SQL code:
update 表table set A=left(B,charindex('*',B)-1)
都是牛人啊。
没多少分,呵呵,权当意思下。新手。。不好意思。
相关问答:
我一个项目,有个插入操作,具体是这样的:
我有进货信息表。在出货时选择相应的进货信息,输入数量,选择部门后,点保存按钮,由于网络延时,点一下没有反映,于是用户就又点一下,导致一次插入了两条记录:
例:
......
字段1,字段2.....字段N,Status,ParentID
1,Name1....test1,1,99
1,Name1....test1,3,99
1,Name2....test2,1,101
1,Name2....test2,3,101
1,Name3....test3,2,101
1,Name1....test1,4,101
想要的结果是:
1,Na ......
将一个查询语句赋给一个变量,如下:
DECLARE @STR NVARCHAR(MAX)
SET @STR='SELECT * from SALE_PROD'
怎么样才能执行它呢?
请高手,仁兄,侠姐帮帮忙啊
多谢,可以啦,高手啊
直接执行就行了
exec ......