The code bellow is a sql querry, made in code. I would like to know how to do such stored procedure:
string[] NameSeperated = FullName.Split(' ');
string querryName = @"SELECT StudentID FROM Students WHERE Name = @name";
if (NameSeperated.Length > 1)
querryName += " AND LastName = @lastName";
using (SqlCommand cmd = new SqlCommand(querryName, sqlConn))
{
cmd.Parameters.Add("@name", SqlDbType.VarChar, 50).Value = NameSeperated[0].Trim();
if (NameSeperated.Length == 2)
cmd.Parameters.Add("@lastName", SqlDbType.VarChar, 50).Value = NameSeperated[1].Trim();
else if (NameSeperated.Length == 3)
cmd.Parameters.Add("@lastName", SqlDbType.VarChar, 50).Value = NameSeperated[1].Trim() + " " + NameSeperated[2].Trim();
}