内连接语句,参数和where子句 [英] inner join statement, parameter and where clause
问题描述
我试图使用内部联接语句,参数和where
子句来理解存储过程,但是当使用参数时没有任何反应。 我知道我可以在哪里兑换b $ color = red但我希望参数能够以不同的颜色传递我做错了什么?
exec [dbo]。[spcolor]'blue'
exec [dbo]。[spcolor]'red'
$
更改程序spcolor
(
@color As varchar
)
AS
开始¥b $ b 选择
cn.namesofcars as nameofcars,
c.color为颜色,
st.seatmaterial
FROM [blue]。[dbo]。[cartypes] as cn
内连接[蓝色]。[dbo]。[颜色]为c on cn.colorid = c.colorid
内联[蓝色]。[dbo]。[seattype] as st on cn.seatmaterialid = st.seatmaterialid
其中c.color = @color
结束
I am trying to understand stored procedures using an inner join statement, a parameter and a where
clause, but when using a parameter nothing happens. I know I can make the where
statement c.color = red but I want the parameter to be able to pass in different colors what am i doing wrong
exec [dbo].[spcolor] 'blue'
exec [dbo].[spcolor] 'red'
ALTER PROCEDURE spcolor
(
@color As varchar
)
AS
Begin
select
cn.namesofcars as nameofcars,
c.color as color,
st.seatmaterial
FROM [blue].[dbo].[cartypes] as cn
inner join [blue].[dbo].[colors] as c On cn.colorid = c.colorid
inner join [blue].[dbo].[seattype] as st On cn.seatmaterialid = st.seatmaterialid
where c.color = @color
End
推荐答案
ALTER PROCEDURE spcolor
(
@color As varchar
)
AS
ALTER PROCEDURE spcolor
(
@color As varchar
)
AS
好像你已经忘记了指定varchar参数的长度。在此上下文中,默认值为1,并且值已截断。尝试指定"@color varchar(30)" (或表格栏定义的最大长度)。
It seems you've forgotten to specify a length for the varchar parameter. The default is 1 in this context and the value truncated. Try specifying "@color varchar(30)" (or whatever the defined max length for table column).
这篇关于内连接语句,参数和where子句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!