| Author |
Topic |
|
chriztoph
Posting Yak Master
184 Posts |
Posted - 2009-06-22 : 02:54:17
|
Hi to all,i have this stored proc and i want to pass a parameter like this:ALTER PROCEDURE [dbo].[prcRptInvoicePerCurrency] @AcctgPeriod INT, @ReportCurrencyID INT, @OfficeID INT, @DateFrom DATETIME, @DateTo DATETIMEASBEGIN SELECT * FROM vwGetRptInvoiceRegister WHERE InvoiceDate BETWEEN @DateFrom AND @DateTo AND ReportCurrencyID = @ReportCurrencyID AND AcctgPeriodShortDesc = @AcctgPeriod AND OfficeID LIKE '%@OfficeID%' ORDER BY CustomerName, InvoiceDateEND the line with RED color that i want to apply.. |
|
|
bklr
Master Smack Fu Yak Hacker
1693 Posts |
Posted - 2009-06-22 : 03:01:53
|
| change @officeid as varchar field and cast officeid as varchar field ex :- declare @id varchar(32)select @id = '1,2,5'select empid,empname from emptable where '%,' + @id + ',%' LIKE '%,' + CAST( empid AS VARCHAR(255)) +',%' or use patindex also... |
 |
|
|
chriztoph
Posting Yak Master
184 Posts |
Posted - 2009-06-22 : 03:10:06
|
| i have got an errorConvertion failed when converting the '%,' to datatype int. |
 |
|
|
bklr
Master Smack Fu Yak Hacker
1693 Posts |
Posted - 2009-06-22 : 03:12:34
|
| use convert or cast function to convert int value to varchar field see example given to u empid is integer field in given query |
 |
|
|
chriztoph
Posting Yak Master
184 Posts |
Posted - 2009-06-22 : 03:21:06
|
i tried it but there is no output..ALTER PROCEDURE [dbo].[prcRptInvoicePerCurrency] @AcctgPeriod INT, @ReportCurrencyID INT, @OfficeID INT, @DateFrom DATETIME, @DateTo DATETIMEASBEGIN SELECT * FROM vwGetRptInvoiceRegister WHERE InvoiceDate BETWEEN @DateFrom AND @DateTo AND ReportCurrencyID = @ReportCurrencyID AND AcctgPeriodShortDesc = @AcctgPeriod AND OfficeID LIKE CAST(@OfficeID AS VARCHAR(255) + '%' ORDER BY CustomerName, InvoiceDateEND what i want is even the '@Office' is null it should be show all Office |
 |
|
|
Nageswar9
Aged Yak Warrior
600 Posts |
Posted - 2009-06-22 : 03:22:46
|
| Hi try like this ALTER PROCEDURE [dbo].[prcRptInvoicePerCurrency] @AcctgPeriod INT, @ReportCurrencyID INT, @OfficeID INT, @DateFrom DATETIME, @DateTo DATETIMEASBEGIN SELECT * FROM vwGetRptInvoiceRegister WHERE InvoiceDate BETWEEN @DateFrom AND @DateTo AND ReportCurrencyID = @ReportCurrencyID AND AcctgPeriodShortDesc = @AcctgPeriod AND patindex('%,'+cast(OfficeID as varchar(10))+',%' , ','+@OfficeID+',') > 0 ORDER BY CustomerName, InvoiceDateEND |
 |
|
|
bklr
Master Smack Fu Yak Hacker
1693 Posts |
Posted - 2009-06-22 : 03:26:06
|
| [code]ALTER PROCEDURE [dbo].[prcRptInvoicePerCurrency] @AcctgPeriod INT, @ReportCurrencyID INT, @OfficeID INT = NULL, @DateFrom DATETIME, @DateTo DATETIMEASBEGIN SELECT * FROM vwGetRptInvoiceRegister WHERE InvoiceDate BETWEEN @DateFrom AND @DateTo AND ReportCurrencyID = @ReportCurrencyID AND AcctgPeriodShortDesc = @AcctgPeriod AND (@OfficeID IS NULL OR OfficeID LIKE CAST(@OfficeID AS VARCHAR(255) + '%') ORDER BY CustomerName, InvoiceDateEND[/code]if officeid in table structure is varchar above will work if it is int then use this (@OfficeID IS NULL OR '%,' + CAST(@OfficeID AS VARCHAR(255) + ',%' LIKE '%,' + CAST( officeid AS VARCHAR(255)) +',%' [/code] |
 |
|
|
chriztoph
Posting Yak Master
184 Posts |
Posted - 2009-06-22 : 03:26:36
|
| got an error:Msg 8116, Level 16, State 1, Procedure prcRptInvoicePerCurrency, Line 20Argument data type int is invalid for argument 2 of patindex function. |
 |
|
|
Nageswar9
Aged Yak Warrior
600 Posts |
Posted - 2009-06-22 : 03:29:02
|
quote: Originally posted by chriztoph got an error:Msg 8116, Level 16, State 1, Procedure prcRptInvoicePerCurrency, Line 20Argument data type int is invalid for argument 2 of patindex function.
ALTER PROCEDURE [dbo].[prcRptInvoicePerCurrency]@AcctgPeriod INT,@ReportCurrencyID INT,@OfficeID INT,@DateFrom DATETIME,@DateTo DATETIMEASBEGINSELECT * FROM vwGetRptInvoiceRegisterWHERE InvoiceDate BETWEEN @DateFrom AND @DateToAND ReportCurrencyID = @ReportCurrencyIDAND AcctgPeriodShortDesc = @AcctgPeriodAND patindex('%,'+cast(OfficeID as varchar(10))+',%' ,','+ cast(@OfficeID as varchar(10))+',') > 0ORDER BY CustomerName, InvoiceDateEND |
 |
|
|
chriztoph
Posting Yak Master
184 Posts |
Posted - 2009-06-22 : 03:39:22
|
| Thanks for helping Guys..it works in my Report..i think my back end code(C#) is the problem.. |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-06-22 : 04:22:48
|
| Until you pass csv you need onlyOfficeID LIKE '%'+cast(@OfficeID as varchar(10))+'%'MadhivananFailing to plan is Planning to fail |
 |
|
|
|