0

example job id = 110000, 112000, 113000 , i want to check character no 3 from left (2) is not zero, this is my query:

SqlCommand cmd = new SqlCommand(" SELECT [job_id], [name_job] FROM [Job] WHERE LEFT(job_id, 2) = @result3 AND SUBSTRING(job_id, 2, 1) != '0' ORDER BY name_job", con);

 cmd.Parameters.Add("@result3", SqlDbType.Char, 2).Value = result2; //this is the fist 2 character from job_id

  SqlDataAdapter sda = new SqlDataAdapter(cmd);
           DataTable dt = new DataTable();
           con.Open();
           sda.Fill(dt);
           con.Close();

           DropDownList1.DataSource = dt;
           DropDownList1.DataTextField = "job_id";
           DropDownList1.DataValueField = "name_job";
           DropDownList1.DataBind();
  • SQL function `LEFT(string, num_of_chars)` is shortcut of `SUBSTRING(string,1,num_of_chars)`. – Alex Kudryashev Nov 21 '17 at 02:51
  • Assuming you actually looking for SQL solution (like result of https://www.bing.com/search?q=sql+check+nth+character) this is already answered enough times... If you are looking for C# or JS solution - please clarify (i.e. there should be some reason why post is tagged with ASP.Net).. Also I suspect there would be even more similar questions for C#/JS. – Alexei Levenkov Nov 21 '17 at 02:55
  • i was edit my code – samuel henk Nov 21 '17 at 03:00

0 Answers0