Phplayers 2019-04-02
代码如下:
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(); }