用与提出'_'号左右值
select right('b_s',charindex( '_','b_s')-1) ;
select left('b_s',charindex( '_','b_s')-1) ;
select left('b_s',charindex( '_','b_s')-1) as [name] from b13 where zzh=1 ; // as[name]为列名
select case when charindex('_',nnn)>0 then left(nnn,charindex('_',nnn)-1)
else nnn end
from b13
select left(nnn,charindex('_',nnn)-1),right(nnn,len(nnn)-charindex('_',nnn)+1)
from b13
where charindex('_',nnn)>0
SELECT (a.nnn+b.aaa) tx,(a.nnn+b.aaa) ty
FROM b13 a
LEFT JOIN a15 b on (a.zzh=b.zzh)
-----------------------------------------------------
private void button2_Click(object sender, EventArgs e)
{
string zzh = textBox1.Text.Trim().ToString();
string strConnection = "user id=sa;password=;";
strConnection += "database = pubs;server=CHINESE-D834096";
//strConnection += "Connect Timeout=30";
string SelectOneStr = "select nnn from b13 where zzh='" + zzh + "'";
SqlConnection Sqlcon = new SqlConnection(strConnection);
SqlCommand Sqlcom = new SqlCommand(SelectOneStr, Sqlcon);
Sqlcon.Open();
SqlDataReader dbRead = Sqlcom.ExecuteReader();
if (dbRead.Read())
{
string qqq = dbRead["nnn"].ToString();
dbRead.Close();
string SelectOneStr1 = "select left('" +qqq+ "',charindex( '_','"+qqq+"')-1) as [name1] from b13 where zzh=1";
SqlConnection Sqlcon1 = new SqlConnection(strConnection);
SqlCommand Sqlcom1 = new SqlCommand(SelectOneStr1, Sqlcon1);
Sqlcon1.Open();
SqlDataReader dbRead1 = Sqlcom1.ExecuteReader();
if (dbRead1.Read())
{
string wwq = dbRead1["name1"].ToString();
//textBox3.Text = wwq;
}
}
string SelectOneStr2 = "select aaa from a15 where zzh='" + zzh + "'";
SqlConnection Sqlcon2 = new SqlConnection(strConnection);
SqlCommand Sqlcom2 = new SqlCommand(SelectOneStr2, Sqlcon2);
Sqlcon2.Open();
SqlDataReader dbRead2 = Sqlcom2.ExecuteReader();
if (dbRead2.Read())
{
string vvv = dbRead2["aaa"].ToString();
dbRead2.Close();
string SelectOneStr4 = "select left('" +vvv+ "',charindex( ',','" +vvv+ "')-1) as [name2] from a15 where zzh=1";
SqlConnection Sqlcon4 = new SqlConnection(strConnection);
SqlCommand Sqlcom4 = new SqlCommand(SelectOneStr4, Sqlcon4);
Sqlcon4.Open();
SqlDataReader dbRead4 = Sqlcom4.ExecuteReader();
if (dbRead4.Read())
{
string wwa = dbRead4["name2"].ToString();
textBox3.Text = wwa;
}
}
//select right('b_s',charindex( '_','b_s')-1) ;
//select left('b_s',charindex( '_','b_s')-1) ;
}