简体   繁体   中英

Remove "" from string or in SQL varchar

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')

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();
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM