Я привязываю, чтобы читать значения в SQl.Как читать значения в SQL
Я создаю один заказ на покупку Если предполагается, что какой-либо орган обновил цену для инвентаря, я сначала проверяю, что цена доступна или нет.
Если эта цена недоступна, тогда я впервые ввожу эту цену в базу данных &, а затем карту новую цену с инвентарем.
Я уже достиг этой функциональности, но я написал пять встроенных запросов для этого сейчас мне нужно, чтобы изменить код & заменить на одну хранимую процедуру. & как я могу написать логику в SQL
Вот мой код с объяснением
//Checking that Buying Price Is Exist or not
//string CheckingIBM = "select * from RS_Inventory_Buying_Master where buying_price ='" + UpdatedPrice + "'";
//cm.TableConnect(CheckingIBM);
//If Buying Price is Exist then Update PIIM table with new buying_product_id
if (cmIS_Price_Exist.rs.Read())
{
//If Buying Price is Exist then Update PIIM table with new buying_product_id
common cm1 = new common();
string BuyingProductId = cmIS_Price_Exist.rs["buying_product_id"].ToString();
string UpdatePIIM = "update RS_Purchase_Invoice_Info_Master set buying_product_id = '" + BuyingProductId + "', qty = '" + UpdatedQuantity + "',tax_id ='" + TaxDetails + "',picreated = 1 where purchase_order_no = '" + PO + "' and product_id = '" + ProductId + "'";
cm1.TableInsert(UpdatePIIM);
cm1.con.Close();
}
//If Buying Price does not Exist then first Insert the price & then Update the other tables
else
{
//If Price is not exist then firsrt insert the price
common cm2 = new common();
string InsertBuyingPrice = "insert into RS_Inventory_Buying_Master (buying_price,latest) values ('" + UpdatedPrice + "','0')";
cm2.TableInsert(InsertBuyingPrice);
cm2.con.Close();
//After inserting the price find the buying product Id of that price
common cm3 = new common();
string FindingUpdatedPrice = "select * from RS_Inventory_Buying_Master where buying_price ='" + UpdatedPrice + "'";
cm3.TableConnect(FindingUpdatedPrice);
//Now finallly after finding the buying price id by using the inserted Price. Now update the buying product id of PIIM
if (cm3.rs.Read())
{
string BuyingProductId = cm3.rs["buying_product_id"].ToString();
//Now finallly after finding the buying price id. Now update the buying product id of PIIM
common cm4 = new common();
string UpdatePIIM = "update RS_Purchase_Invoice_Info_Master set buying_product_id = '" + BuyingProductId + "', qty = '" + UpdatedQuantity + "',tax_id ='" + TaxDetails + "',picreated = 1 where purchase_order_no = '" + PO + "' and product_id = '" + ProductId + "'";
cm4.TableInsert(UpdatePIIM);
cm4.con.Close();
}
cm3.con.Close();
}
Любой suggesion будет оценен.
Вы должны начать с разработки параметров, которые должна храниться в хранимой процедуре, а затем узнать синтаксис команды 'CREATE PROCEDURE' в SQL и запустить с этим. –
Я знаю, как создать хранимую процедуру. Моя хранимая процедура примет все параметры, которые находятся в запросе, но проблема в том, как проверить, что цена отсутствует в базе данных, а если нет, тогда вставьте новую цену в базу данных. –
задает ваш вопрос относятся к чтению значений в SQL? с чем вы столкнулись: создание процедуры? основная логика вашей системы? – Randy