Я изо всех сил пытаюсь заставить свой запрос работать в С# usng select * into statement, который скопирует данные таблицы и создаст новую таблицу.
using (SqlConnection con = new SqlConnection(connectionstring))
{
con.Open();
using (SqlCommand cmd = new SqlCommand("select pp.upc as upc , pp.description as Description,sp.qty_onhand as Qty" +
"into TempProductProfile from product_profile pp" +
"inner join store_products sp on" +
"pp.upc = sp.upc" +
"order by pp.description", con))
cmd.executenonquery(): <-- got error here
}
Может ли кто-нибудь указать мне правильный путь?. благодаря
using (SqlConnection con = new SqlConnection(connectionstring))
{
con.Open();
using (SqlCommand cmd = new SqlCommand(@"select pp.upc as upc , pp.description as Description,sp.qty_onhand as Qty
into TempProductProfile from product_profile pp
inner join store_products sp on
pp.upc = sp.upc
order by pp.description", con))
cmd.executenonquery(): <-- got error here
}
Напишите запрос как this.With @
вы можете написать строку на более чем одной строке! Проблема в объяснении Grant Winney
о неправильной конкатенации строк.
Ваш запрос, как и сейчас, будет выглядеть примерно так:
... sp.qty_onhand как Qtyinto TempProductProfile из product_profile ppinner join...
Вам нужно вставить пробел в начале каждой линии, которую вы объединяете:
using (SqlCommand cmd = new SqlCommand(
"select pp.upc as upc , pp.description as Description,sp.qty_onhand as Qty" +
" into TempProductProfile from product_profile pp" +
" inner join store_products sp on" +
" pp.upc = sp.upc" +
" order by pp.description", con))
Поместите пробел в начале каждой строки текста, исключая первый.
Поскольку у вас нет пробелов между строками текста, ваш SQL
select pp.upc as upc , pp.description as Description,sp.qty_onhand as Qtyinto TempProductProfile from product_profile ppinner join store_products sp onpp.upc = sp.upcorder by pp.description