这篇文章主要为大家详细介绍了SQL Server SQL 截取字符串应用代码,具有一定的参考价值,可以用来参考一下。
感兴趣的小伙伴,下面一起跟随四海网的小编两巴掌来看看吧!
SUBSTRING代码如下:
Declare @S1 varchar(100)
Select @S1='http://www.163.com'
Select Left(@S1,4)
代码如下:
Declare @S1 varchar(100)
Select @S1='http://www.163.com'
Select right(@S1,11)
代码如下:
Declare @S1 varchar(100)
Select @S1='http://www.163.com'
Select SUBSTRING(@S1,8,3)
------------------------------------
代码如下:
Declare @S1 varchar(100)
Select @S1='http://www.163.com'
Select Substring(@S1,CHARINDEX('www',@S1)+1,Len(@S1))
/*此处也可以这样写:Select Substring(@S1,CHARINDEX('//',@S1)+2,Len(@S1))*/
代码如下:
Declare @S1 varchar(100)
Select @S1='http://www.163.com'
Select Substring(@S1,PATINDEX('%www%',@S1)+1,Len(@S1))
--此处也可以这样写:Select Substring(@S1,PATINDEX('%//%',@S1)+2,Len(@S1))
代码如下:
Declare @S1 varchar(100)
Select @S1='http://www.163.com'
Select REPLACE(@S1,'http://','')
代码如下:
Declare @S1 varchar(100)
Select @S1='http://www.163.com'
Select STUFF(@S1,CHARINDEX('http://',@S1),Len('http://'),'')
代码如下:
Declare @S1 varchar(100)
Select @S1='C:\Windows\test.txt'
select right(@S1,charindex('\',REVERSE(@S1))-1)
代码如下:
private void DDL_AreaBind()
{
conn = new SqlConnection(ConfigurationManager.ConnectionStrings["strcon"].ConnectionString);
string str = "0000";
cmd = new SqlCommand("select AreaID,Name=ltrim(Name) from Area where right(AreaID,4) ='" + str + "'", conn);
SqlDataAdapter sda = new SqlDataAdapter(cmd);
sda.Fill(ds, "area");
this.ddl_area.DataSource = ds.Tables["area"].DefaultView;
this.ddl_area.DataTextField = "Name";
this.ddl_area.DataValueField = "AreaID";
this.ddl_area.DataBind();
cmd = new SqlCommand("select * from Area ", conn);
cmd.CommandType = CommandType.Text;
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
adapter.Fill(ds, "city");
this.ddl_city.DataSource = ds.Tables["city"].DefaultView;
this.ddl_city.DataTextField = "Name";
this.ddl_city.DataValueField = "AreaID";
this.ddl_city.DataBind();
}
protected void ddl_area_SelectedIndexChanged(object sender, EventArgs e)
{
conn = new SqlConnection(ConfigurationManager.ConnectionStrings["strcon"].ConnectionString);
this.ddl_city.Enabled = true;
string str1="0000";
cmd = new SqlCommand("select AreaID,Name from Area where substring(AreaID,1,2)='" + this.ddl_area.SelectedValue.Substring(0,2) + "' AND substring(AreaID,3,4) <> '0000' AND substring(AreaID,5,2)='00' ", conn);
cmd.CommandType = CommandType.Text;
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
adapter.Fill(ds, "city");
this.ddl_city.DataSource = ds.Tables["city"].DefaultView;
this.ddl_city.DataTextField = "Name";
this.ddl_city.DataValueField = "AreaID";
this.ddl_city.DataBind();
}
本文来自:http://www.q1010.com/179/7622-0.html
注:关于SQL Server SQL 截取字符串应用代码的内容就先介绍到这里,更多相关文章的可以留意四海网的其他信息。
关键词:SQL SERVER
四海网收集整理一些常用的php代码,JS代码,数据库mysql等技术文章。