在sql中选择特定的行号?

时间:2014-04-28 06:02:49

标签: sql sql-server

有什么方法可以在SQL Server中选择指定的行数? 在这里,我有查询结果看起来像这样

select LEFT(intValue,patindex('%$*%' , intValue) -1) as ID,
   Right(intValue, (LEN(intValue) - (patindex('%$*%' , intValue) + 1)))as Data  
   from dbo.Split('1$*hi,2$*hellow, ',')

ID  |   Data
----------------
 1  |   HI  
 2  |   hellow

这里我想选择特定的行项Data

select LEFT(intValue,patindex('%$*%' , intValue) -1) as ID,
   Right(intValue, (LEN(intValue) - (patindex('%$*%' , intValue) + 1)))as Data  
   from dbo.Split('1$*hi,2$*hellow, ',') ID=1

喜欢ID = 1

的地方

我需要像

这样的结果
Data
-----
 HI

提前致谢

2 个答案:

答案 0 :(得分:1)

With CTE As (
select LEFT(intValue,patindex('%$*%' , intValue) -1) as ID,
   Right(intValue, (LEN(intValue) - (patindex('%$*%' , intValue) + 1)))as Data  
   from dbo.Split('1$*hi,2$*hellow, ',')
)
Select * From CTE Where ID = 1

答案 1 :(得分:1)

select Right(intValue, (LEN(intValue) - (patindex('%$*%' , intValue) + 1)))as Data
from dbo.Split('1$*hi,2$*hellow,3$*Acronym', ',') where LEFT(intValue,patindex('%$*%' , intValue) -1) = 1

相关问题