当前位置: 代码迷 >> Sql Server >> 怎么获取空格以前的数据
  详细解决方案

怎么获取空格以前的数据

热度:94   发布时间:2016-04-27 21:00:44.0
如何获取空格以前的数据
比如字段是
123     1323
asdas   asd
那么我想得到结果是
123
asdas

------解决方案--------------------
写反了.

select left(字段 , charindex( ' ' , 字段) - 1) from tb

------解决方案--------------------
先要drop掉test表.
ALTER PROCEDURE [dbo].[testProc]
AS
BEGIN
if exists(select 1 from sysobjects where xtype= 'U ' and name= 'test ')
drop table test
declare @test int;
select count(*) as c into test from table2;
print @test

END
------解决方案--------------------
select a,left(a,charindex( ' ',a)) FROM test
  相关解决方案