在SQL中使用ALTER PROC时连接另一个表

在SQL中使用ALTER PROC时连接另一个表,sql,sql-server,asp-classic,alter,proc,Sql,Sql Server,Asp Classic,Alter,Proc,对你们来说很简单 关于连接表等的线程很多。但是,我还没有找到一个同样涉及alterprocsql的线程 我的任务很简单 我只需要将一个名为“STOCK_DESCRIPTORS”的表连接到下面的SQL,以便在我的数据库网站上显示它 USE [ShopDatabase] GO /****** Object: StoredProcedure [dbo].[stpGet_StockUnitDetails] Script Date: 09/17/2013 12:03:05 *****

对你们来说很简单

关于连接表等的线程很多。但是,我还没有找到一个同样涉及alterprocsql的线程

我的任务很简单

我只需要将一个名为“STOCK_DESCRIPTORS”的表连接到下面的SQL,以便在我的数据库网站上显示它

USE [ShopDatabase]
GO
/****** Object:  StoredProcedure [dbo].[stpGet_StockUnitDetails]    Script Date:    09/17/2013     12:03:05 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROC [dbo].[stpGet_StockUnitDetails]
@strStockUnitCode nvarchar(250)
As
SELECT * from VIEWSTOCKUNIT Where strStockUnitCode = @strStockUnitCode
我只是尝试补充: 从VIEWSTOCKUNIT、STOCK_描述符中选择*
其中strStockUnitCode=@strStockUnitCode


但是,虽然这会成功解析,但会弄乱.ASP(两个表上都存在strStockUnitCode)

您所要做的就是将表连接在一起:

确保将*更改为代码所需的列。选择所有列是不好的做法

USE [ShopDatabase]
GO
/****** Object:  StoredProcedure [dbo].[stpGet_StockUnitDetails]    Script Date:    09/17/2013     12:03:05 ******/
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROC [dbo].[stpGet_StockUnitDetails]
@strStockUnitCode nvarchar(250)
As
SELECT 
     * -- change this to be the columns your code needs
 from VIEWSTOCKUNIT a
inner join STOCK_DESCRIPTORS b on a.strStockUnitCode = b.strStockUnitCode
 Where a.strStockUnitCode = @strStockUnitCode

您好,谢谢您的回复,很有效!现在唯一的问题是它会干扰另一个不相关的SQL(现在没有显示!)。