简体   繁体   中英

Create stored procedure on SQL Server

I have to create a stored Procedure in a Database (SQL Server)

    string query = "CREATE PROCEDURE  queryName AS BEGIN " + sqlCommand + " END";
    SqlConnection cnn;
    SqlConnectionStringBuilder builder = new System.Data.SqlClient.SqlConnectionStringBuilder();
    //builder["Provider"] = provider;
    builder["Server"] = @"Themis\DEV";

    builder["Integrated Security"] = "SSPI";
    string connection_string = builder.ConnectionString;

    cnn = new SqlConnection(connection_string);

    cnn.Open();


    SqlCommand sqlCmd = new SqlCommand(queryName, cnn);
    sqlCmd.CommandText = query;
    sqlCmd.Connection = cnn;
    sqlCmd.CommandType = CommandType.Text;
    sqlCmd.ExecuteNonQuery();

But I get an Errormessage

Incorrect syntax near INNER

The Procedure is like this

UPDATE description 
       INNER JOIN description1 
               ON description.resid_ = description1.resid_ 
SET    description.polish = [description1].[polish] 
WHERE  (description1.polish <> '') 
AND    (description1.polish <> ( '-' )); 

That is not a valid Update using Join syntax in SQL SERVER . Try this way

UPDATE D 
SET    D.polish = [D1].[polish] 
FROM   description D 
       INNER JOIN description1 D1 
               ON D.resid_ = D1.resid_ 
WHERE  D1.polish <> '' 
       AND D1.polish <> '-'; 

Where clause can be simplified using NOT IN

Where D1.polish NOT IN ('','-')

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