create procedure InsertMovies
(
@Title nvarchar(max),
@Sdesc nvarchar(max),
@LDesc nvarchar(max),
@ImgUrl nvarchar(max),
@TicketCost real,
@Seat int,
@StrDate DateTime,
@EndDate DateTime,
@CineName nvarchar(max))
AS
BEGIN
Declare @temp int
SET @temp = Convert(int,'select Id from [dbo].[Cinemas] where [Location] = @CineName')
INSERT INTO [dbo].[MovieSessions]
(
[Title],
[ShortDescription],
[LongDescription],
[ImageUrl],
[Price],
[Seats],
[StartTime],
[EndTime],
[Cinemas_Id]
)
values
(
@Title,
@Sdesc,
@LDesc,
@ImgUrl,
@TicketCost,
@Seat,
@StrDate,
@EndDate,
@temp
)
END
GO
请帮我正确地从select语句中转换值,我可以创建这个程序但是我在执行时遇到错误,这里是错误
Msg 245,Level 16,State 1,Procedure InsertMovies,Line 6
转换varchar值时转换失败'从中选择ID [dbo]。[电影院] [Location] = @ CineName'数据类型int。
答案 0 :(得分:2)
这部分是您的问题...您将整个查询文本转换为int
SET @temp = Convert(int,'select Id from [dbo].[Cinemas] where [Location] = @CineName')
尝试这样
SET @temp = (select Id from [dbo].[Cinemas] where [Location] = @CineName)
要确认,您在Cinemas表中的ID字段是int类型吗?
答案 1 :(得分:0)
在查询中用括号替换单引号:
SET @temp = Convert(int,(select Id from [dbo].[Cinemas] where [Location] = @CineName))
答案 2 :(得分:0)
您没有转换特定的int
。事实上,您正在尝试将字符串'select Id from [dbo].[Cinemas] where [Location] = @CineName'
转换为int
,这是不正确的。尝试改变:
SET @temp = Convert(int,(select Id from [dbo].[Cinemas] where [Location] = @CineName))
答案 3 :(得分:0)
您可以使用此代码:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>
<body>
<?php
$Realisateurs=array(" James Cameron", " David O. Russell", " Woody Allen" , " Michael Haneke");
?>
<?php
for($i=0;$i<4;$i++)
{
?>
<input type="radio" name"group1" value="<? $Realisateurs[$i] ?>"><?php echo $Realisateurs[$i] ?><br>
<?php
}
?>
</body>
</html>
答案 4 :(得分:0)
试试这个:
SET @temp = cast((从[dbo]中选择前1名。[电影院]其中[位置] = @CineName)as int)
使用top 1来避免乘法结果错误
答案 5 :(得分:0)
简单方法:
private Vector2 position;
private Vector2 positionMoveTarget;
private float width;
private float height;
private Rectangle DamnBlock; /* Hit detection test */
/* CODE CODE CODE */
if(this.getPositionMoveTarget() != null ){
if(this.getPosition() == this.getPositionMoveTarget()){
this.setPositionMoveTarget(null);
} else {
Vector2 tmpPosition = new Vector2(this.getPosition());
Vector2 tmpPositionMoveTarget = new Vector2(this.getPositionMoveTarget());
Vector2 velocity = new Vector2(tmpPositionMoveTarget).sub(tmpPosition).nor().scl(this.getMoveSpeed()*delta);
Vector2 tmpPositionWithVelocety = new Vector2(tmpPosition).add(velocity);
if(new Rectangle(tmpPositionWithVelocety.x, tmpPositionWithVelocety.y,this.getWidth(),this.getHeight()).overlaps(DamnBlock)){
/*
Calculate the biggest possible "velocety * ( delta - X )", in order to sit directly next to DamnBlock.
But how ?
*/
} else {
if(tmpPosition.dst2(tmpPositionMoveTarget)<tmpPosition.dst2(tmpPositionWithVelocety)){
this.setPosition(this.getPositionMoveTarget());
this.setPositionMoveTarget(null);
} else {
this.setPosition(tmpPositionWithVelocety);
}
}
}
}