CREATE FUNCTION [dbo].[getCharByCount] (@sSource varchar(1000),@sValue varchar(10),@iOrder INT)
RETURNS VARCHAR(10) AS
BEGIN
declare @iPos INT
DECLARE @iPos1 INT
DECLARE @sSplit VARCHAR(10)
declare @i INT
IF @sSource is NULL
RETURN ''
set @sSplit =''
set @i = 1
set @iPos = 1
SET @iPos1 = 1
while @iPos >0
begin
set @iPos = charindex(@sValue,@sSource,@iPos1)
if(@iPos >0)
begin
IF @iOrder = @i
BEGIN
SET @sSplit = SUBSTRING(@sSource,@iPos1,@iPos-@iPos1)
SET @iPos = -1
END
ELSE
BEGIN
set @iPos1 = @iPos + 1
set @i = @i +1
END
END
ELSE
BEGIN
IF @iPos1 >0
IF @iOrder = @i
SET @sSplit = SUBSTRING(@sSource,@iPos1,1000)
SET @iPos1 = -1
END
end
return @sSplit
END
go
--如下查询就可以实现你的功能
SELECT dbo.getCharByCount(num,',',1) num1,dbo.getCharByCount(num,',',2) num2,dbo.getCharByCount(num,',',3) num3,dbo.getCharByCount(num,',',4) num4,dbo.getCharByCount(num,',',5) num5 from 表
要保存价值的具体情况,如J = 5,然后使用的分配继续就行了。代码:
字符串的GetValues????=“”
诠释计数= 0
(i = 0<10i + +)
{ BR />(我== 5)
{
GetValue的= I / /获取值
Continue(继续)
}
计数+ +...... />}
大概意思是,专门写
头文件添加using System.Data
using System.Data.SqlClient
创建链接
SqlConnection con = new SqlConnection()
con.ConnectionString = "server=服务器ipdatabase=数据库名uid=数据库账户pwd=密码"
con.Open()
写sql语句
SqlCommand com = new SqlCommand()
com.Connection = con
com.CommandType = CommandType.Text
com.CommandText = "sql语句"
SqlDataReader dr = com.ExecuteReader()//执行SQL语句
SqlDataReader dx = dr//执行SQL语句
取数据
while (dr.Read())--类似指针
{ cs5 = String.Format("{0}_{1}_{2}", dr[9], dr[10], dr[11]) }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)