首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

请问,这段SQL语句应该如何写

2012-01-02 
请教,这段SQL语句应该怎么写?privatevoidSearch(){stringssqlselectdistincta.STAFF_ID,a.CNNAME,a.DEPT

请教,这段SQL语句应该怎么写?
private   void   Search()
                {
                        string   ssql   =   "select   distinct   a.STAFF_ID,a.CNNAME,a.DEPT,a.TECHPOS,a.EDULEVEL,a.ATTACH_DATE,b.M_SKILL,b.M_TYPE,c.LANGUAGE ";
                        ssql   +=   "   from   D_STAFF_BASE   a,D_SKILL_VIEW   b,D_STAFF_LANG_ABILITY   c ";
                       
                        //根据姓名查询
                        if   (this.TextBox1.Text.Trim()   !=   " ")
                        {
                             
                                ssql   +=   "   where   a.CNNAME= ' "+this.TextBox1.Text.Trim()+ " ' ";
                        }

                        //根据技能查询
                        if   (this.TextBox3.Text.Trim()   !=   " ")
                        {
                               
                                ssql   +=   "   where   b.M_SKILL= ' "+this.TextBox3.Text.Trim()+ " 'or   b.M_TYPE= ' "+this.TextBox3.Text.Trim()+ " ' ";
                        }

                        //根据语言查询
                        if   (this.Languageddl.SelectedValue!= " ")
                        {
                                ssql   +=   "   where   c.LANGUAGE= ' "+this.Languageddl.DataValueField+ " ' ";
                        }
                       
                        //根据职称查询
                        if   (this.Techposddl.SelectedValue   !=   " ")
                        {
                                ssql   +=   "   where   a.TECHPOS= ' "+this.Techposddl.DataValueField+ " ' ";


                        }
                        if   (this.Deptddl.SelectedValue   !=   " ")
                        {
                                ssql   +=   "   where   a.DEPT= ' "+this.Deptddl.DataValueField+ " ' ";
                        }    
                        //GridView1.DataSourceID   =   "SqlDataSource1 ";
                        this.SqlDataSource1.SelectCommand   =   ssql;
                        this.DataBind();
 
                }
根据不同的情况查询,我的这个SQL语句老是写不对,应该怎么写啊?

[解决办法]
改 ssql += " from D_STAFF_BASE a,D_SKILL_VIEW b,D_STAFF_LANG_ABILITY c where 1=1 ";
然后
//根据姓名查询
if (this.TextBox1.Text.Trim() != " ")
{

ssql += " and a.CNNAME= ' "+this.TextBox1.Text.Trim()+ " ' ";
}
后面的都将“Where”改为“and”

热点排行