本文介绍了多个检查SQL表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我有两张表格如下



1.ItemCode(string),ItemName(string),以及一些名为ItemMaster的字段。

2.ItemCode(string),BranchName(字符串),Qty(int)和....调用股票



我想从第二个表中检索数据如果分支和ItemName是正确的。



我没有传递ItemCode字段,我的搜索字段是ItemName。我怎么能做到这一点。请帮我找到解决方案



项目代码案例我写了storedproc

I have two tables as follows

1.ItemCode(string),ItemName(string),and some more field called ItemMaster.
2.ItemCode(string),BranchName(string),Qty(int) and .... called Stocks

I want to retrieve the data from second table if the Branch and "ItemName" are correct.

Am not passing "ItemCode" field my search field is ItemName. how I can achieve this. please help me to find solution

in itemcode case I write the storedproc

Alter Procedure ItemShow
 @BranchName varchar(20) = NULL,
 @ItemCode varchar(20) = NULL
 As
 Begin
SELECT Distinct StockInBranches.ItemCode,StockInBranches.BranchName,StockInBranches.Price,StockInBranches.Qty

	FROM StockInBranches
Inner Join ItemMaster On
   StockInBranches.ItemCode= @ItemCode
 WHERE StockInBranches.BranchName=@BranchName
 End





怎么写itemname的情况?请检查。



how to write in itemname case? please check.

推荐答案

ELECT Distinct StockInBranches.ItemCode,StockInBranches.BranchName,StockInBranches.Price,StockInBranches.Qty

    FROM StockInBranches
Inner Join ItemMaster On
   StockInBranches.ItemCode= ItemMaster.ItemCode
 WHERE StockInBranches.BranchName=@BranchName and (@ItemCode is null or StockInBranches.ItemCode = @ItemCode)





if你只需要传递BranchName然后



if you only need to pass BranchName only then

ELECT Distinct StockInBranches.ItemCode,StockInBranches.BranchName,StockInBranches.Price,StockInBranches.Qty

    FROM StockInBranches
Inner Join ItemMaster On
   StockInBranches.ItemCode= ItemMaster.ItemCode
 WHERE StockInBranches.BranchName=@BranchName


这篇关于多个检查SQL表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-07 19:42