using (var connection = connection string)using (var command = new SqlCommand()){command.Connection = connection;command.CommandText =
@"DECLARE @Enabled INT; " +@"SET @Enabled = " +
@"DECLARE @Enabled INT; " +
@"SET @Enabled = " +
@"( " +@"SELECT TOP 2 p.is_active " +@"FROM dbo.[product] p WITH (nolock) " +@"WHERE p.name = @name " +@"); " +
@"( " +
@"SELECT TOP 2 p.is_active " +
@"FROM dbo.[product] p WITH (nolock) " +
@"WHERE p.name = @name " +
@"); " +
@"SELECT Msg = CONVERT( VARCHAR(32), " +@"CASE " +
@"SELECT Msg = CONVERT( VARCHAR(32), " +
@"CASE " +
@"WHEN @Enabled = 0 " + @"THEN 'Record is disabled' " +@"WHEN @Enabled = 2 " + @"THEN 'Record exist in the table' " +
@"WHEN @Enabled = 0 " +
@"THEN 'Record is disabled' " +
@"WHEN @Enabled = 2 " +
@"THEN 'Record exist in the table' " +
@"ELSE ''";@"END);";
@"ELSE ''";
@"END);";
command.Parameters.AddWithValue("name", name);command.CommandTimeout = 100;connection.Open();command.ExecuteNonQuery();string message = (string)command.ExecuteScalar();connection.Close();return message;}return string.Empty;