You need to decalre MaxImageCnt as a variable, i.e. DECLARE
@MaxImageCnt int
You then reference it as @MaxImageCnt

Altered code below:

ALTER PROCEDURE dbo.InsertImage
        (
        @ImagePath varchar(50),
        @UserId varchar(10),
        @ImageCnt int
        )
AS
BEGIN
        DECLARE @MaxImageCnt  int

        SELECT MAX(ImageCnt) AS @MaxImageCnt FROM userImages
        WHERE ImagePath LIKE @ImagePath+'%'

         IF @MaxImageCnt!=NULL
                SET @[EMAIL PROTECTED]
                SET @[EMAIL PROTECTED](@MaxImageCnt AS
varchar)

        INSERT UserImages (ImagePath,UserId,ImageCnt) VALUES
(@ImagePath,@UserId,@ImageCnt)
END

On 23 Nov, 22:26, BigJ <[EMAIL PROTECTED]> wrote:
> My procedure code:
>
> ALTER PROCEDURE dbo.InsertImage
>         (
>         @ImagePath varchar(50),
>         @UserId varchar(10),
>         @ImageCnt int
>         )
> AS
> BEGIN
>         SELECT MAX(ImageCnt) AS MaxImageCnt FROM userImages
>         WHERE ImagePath LIKE @ImagePath+'%'
>
>          IF MaxImageCnt!=NULL
>                 SET @[EMAIL PROTECTED]
>                 SET @[EMAIL PROTECTED](MaxImageCnt AS varchar)
>
>         INSERT UserImages (ImagePath,UserId,ImageCnt) VALUES
> (@ImagePath,@UserId,@ImageCnt)
> END
>
> My question is how do you set a variable to the result of the SELECT
> query, which should be in MaxImageCnt. When I try to save this, it
> tells me that the compiler is basically trying to find a column caled
> MaxImageCnt, which makes sense.  I guess this is a completely newie
> syntactical issue, but i can't find anything on it.  i know there is
> also other lopsided bad syntax in this procedure too, but please
> ignore that and if possible provide insight to the problem i
> asked...thanks guys.
>
> Jon

Reply via email to