日期:2014-05-17 浏览次数:20618 次
----------------------------
-- Author :DBA_Huangzj(發糞塗牆)
-- Date :2013-03-22 14:04:42
-- Version:
-- Microsoft SQL Server 2008 R2 (SP1) - 10.50.2500.0 (X64)
-- Jun 17 2011 00:54:03
-- Copyright (c) Microsoft Corporation
-- Enterprise Edition (64-bit) on Windows NT 6.1 <X64> (Build 7601: Service Pack 1, v.721)
--
----------------------------
--> 测试数据:[huang]
if object_id('[huang]') is not null drop table [huang]
go
create table [huang]([品名规格] varchar(17),[装数] sql_variant)
insert [huang]
select '笋丝香辣味80g*6',null union all
select '笋丝五香味75g*120',null union all
select '五香豆干100g*30',null union all
select '梅菜笋丝43g*100',null
--------------开始查询--------------------------
select SUBSTRING([品名规格],1,PATINDEX('%*%',[品名规格])-1) [品名规格],SUBSTRING([品名规格],PATINDEX('%*%',[品名规格])+1,LEN(PATINDEX('%*%',[品名规格])))[装数]
from [huang]
----------------结果----------------------------
/*
品名规格 装数
----------------- -----------------
笋丝香辣味80g 6
笋丝五香味75g 1
五香豆干100g 3
梅菜笋丝43g 1
*/