Home > Enterprise >  Remove "" from string or in SQL varchar
Remove "" from string or in SQL varchar

Time:12-17

Is it even possible to return value of string without the " " ?

I have the following string: Chb = "NOT";

Now i either want to remove the "" in C# or SQL.

so i want to have either Chb = NOT in C# ,or i want to remove the ' ' in SQL that i get in @Chb so that this: WHERE PAR @Chb IN ('1','2','3')

isnt like this : WHERE PAR 'NOT' IN ('1','2','3')

but it is like this WHERE PAR NOT IN ('1','2','3')

CodePudding user response:

I don't believe this is the right approach for this.

If you want to execute a command in SQL which comes from a C# code, then i would do:

string exists = "select * from table where var in (1,2,3)";
string notExists = "select * from table where var NOT in (1,2,3)";

if (chb != "NOT")
{
   SqlCommand cmd = new SqlCommand(exists, con);
   cmd.ExecuteScalar();
}
else
{
   SqlCommand cmd = new SqlCommand(notExists, con);
   cmd.ExecuteScalar();
}
  • Related