Dear all..
I have a table as -
| ID | User | Location | Flag |
| 1 | Ashok | Mumbai | 1 |
| 2 | Reema | Mumbai | 1 |
| 3 | Kesar | Haryana | 1 |
| 4 | Hardik | Kolkata | 1 |
| 5 | Rajat | Kolkata | 1 |
Front-End -
1. CheckListbox - List of users.
2. CheckListbox - List of Locations.
User can select multiple Users or/and Locations.
For null values (eg - if no Location is selected, System.DBValue.Null is passed)
1. If User - Ashok, then only one record must be displayed.
SQL Stored Procedure -
@User varchar(max),
@Location varchar(max)
declare @SQLQuery nvarchar(4000)
declare @Whereclause nvarchar(4000)
set @SQLQuery = 'select ID, User, Location from UserLocationTable where Flag = 1'
if @User is not null
set @Whereclause =' and User in ('+@User+)'
if @Location is not null
set @Whereclause =' and Location in ('+@Location+)'
set @SQLQuery = @SQLQuery + @Whereclause -
Issue - Passing System.DBNull.Value.ToString() from front-end makes the query as -
select ID, User, Location from UserLocationTable where Flag =1 and Location in ('')
and User in ('Ashok')
----------
How to solve this ?? Please guide
Midhun TpPosted Dec 26, 2016, 5:05 AM
Rafnas T PPosted Jan 25, 2017, 7:05 AM
@Location varchar(max)
declare @SQLQuery nvarchar(4000)
declare @Whereclause nvarchar(4000)
set @SQLQuery = 'select ID, User, Location from UserLocationTable where Flag = 1'
if @User is not null
set @Whereclause =' and User in ('+@User+')'
if @Location is not null
set @Whereclause =' and Location in ('+@Location+')'
set @SQLQuery = @SQLQuery + @Whereclause
Riddhi ValechaPosted Dec 27, 2016, 7:56 AM
Fabio Silva LimaPosted Dec 27, 2016, 5:44 AM
Midhun TpPosted Dec 27, 2016, 5:37 AM
Riddhi ValechaPosted Dec 27, 2016, 5:30 AM
Any idea - what value can I pass from front-end ?
I tried passing -"", String.Empty, null - But none worked..
What value to pass from front-end and what to write in if-condition
so that I can get the desired query -
select id, location, user from table where user in ('Ashok','reema')
The query that I am getting is -
select id, location, user from table where user in ('Ashok','reema')
Please guide..
Midhun TpPosted Dec 26, 2016, 11:16 PM
Riddhi ValechaPosted Dec 26, 2016, 8:51 AM
Midhun TpPosted Dec 26, 2016, 6:30 AM
Riddhi ValechaPosted Dec 26, 2016, 6:17 AM
sudipta sanyalPosted Dec 26, 2016, 5:45 AM
Manas MohapatraPosted Dec 26, 2016, 5:27 AM
Riddhi ValechaPosted Dec 26, 2016, 5:07 AM
Fabio Silva LimaPosted Dec 26, 2016, 4:31 AM
IF(LEN(ISNULL(Location, 0)) = 0)