aspvbnetnerd
Programmer
I have a procedure like this.
If execute it like this the it is okay
But i should also be able to execute it like this.
Sometimes I want to be able to send these parameters to the stored procedure, depending what the user choses '1,2' but when I send it like this i get an error like this
Conversion failed when converting the varchar value '1,2' to data type int.
The column ID_TYP from table Frekvens_grupp is an INT
Hope you understand my problem
George
Code:
[COLOR=blue]CREATE PROCEDURE[/color] usp_GetSales
@DATEFROM [COLOR=blue]AS VARCHAR(10)[/color],
@DATETO [COLOR=blue]AS VARCHAR(10)[/color],
@ID_TYPE [COLOR=blue]AS VARCHAR(10)[/color]
AS
DECLARE @Sales TABLE(DATUM [COLOR=blue]VARCHAR[/color](10), TIDPUNKT [COLOR=blue]VARCHAR[/color](8), KASSOR [COLOR=blue]INTEGER[/color], KASSA [COLOR=blue]INTEGER[/color], FORS_BRUTTO [COLOR=blue]DECIMAL[/color](12,2), [COLOR=blue]MOMS DECIMAL(12,2)[/color], KUNDER [COLOR=blue]INTEGER[/color], POSTER [COLOR=blue]INTEGER PRIMARY KEY[/color](DATUM, TIDPUNKT, KASSOR, KASSA))
[COLOR=blue]INSERT INTO[/color] @Sales [COLOR=blue]SELECT[/color] DATUM, TIDPUNKT, KASSOR, KASSA, [COLOR=#FF00FF]SUM[/color](FORS_BRUTTO), [COLOR=#FF00FF]SUM[/color](MOMS), [COLOR=#FF00FF]SUM[/color](KUNDER), [COLOR=#FF00FF]SUM[/color](POSTER) [COLOR=blue]FROM[/color] FREKVENS_GRUPP [COLOR=blue]WHERE[/color] DATUM >= @DATEFROM AND DATUM <= @DATETO AND ID_TYP IN (1, 2) [COLOR=blue]GROUP BY[/color] DATUM, TIDPUNKT, KASSOR, KASSA
[COLOR=blue]SELECT[/color] * [COLOR=blue]FROM[/color] @Sales
If execute it like this the it is okay
Code:
usp_GetSales '2006-09-03', '2006-09-03', '1'
But i should also be able to execute it like this.
Sometimes I want to be able to send these parameters to the stored procedure, depending what the user choses '1,2' but when I send it like this i get an error like this
Conversion failed when converting the varchar value '1,2' to data type int.
Code:
usp_GetSales '2006-09-03', '2006-09-03', '1,2'
The column ID_TYP from table Frekvens_grupp is an INT
Hope you understand my problem
George