Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: SQL-Server
declare @vc_supplier_name varchar(200) =''
declare @in_supplier_type_id int =2
declare @bt_active bit
 
SELECT a.in_supplier_id, dbo.format_fnc_bit(1, a.bt_active) AS vc_active, b.vc_supplier_type_name, a.in_supplier_type_id, a.vc_supplier_name,
 
    dbo.admin_user_fnc_get_name(1, a.in_updatedby_user_id) AS vc_updated_by, a.dt_updated
 
    FROM dbo.supplier a
 
    INNER JOIN dbo.common_data_vw_supplier_type b ON a.in_supplier_type_id = b.in_supplier_type_id
 
    WHERE a.in_supplier_type_id = @in_supplier_type_id AND a.vc_supplier_name LIKE '%' + @vc_supplier_name + '%'
    AND  if(@bt_active <> '') a.bt_active= @bt_active
    ORDER BY a.vc_supplier_name


Here I pass bt_active from aps.net page .. So i want to check that if bt_active is passes as 1 then it should filter with Active record else all record should display
Posted 14-Feb-13 10:45am
Edited 14-Feb-13 11:15am
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

The simplest approach is this:
 AND (@bt_active = 0 OR a.bt_active=1)
  Permalink  
Comments
mrinal_kumar_jha at 14-Feb-13 16:06pm
   
Thanks..
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

If @bt_active variable and a.bt_active field can stores only 0 and 1, when 0 means non-active and 1 means active, you need to build query depends on this variable:
IF @bt_active = 1 
BEGIN
    --query to get active records
ELSE
    --query to get all records
END
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 383
1 Sascha Lefévre 215
2 Maciej Los 185
3 Abhinav S 170
4 Richard Deeming 155
0 Sergey Alexandrovich Kryukov 7,141
1 OriginalGriff 6,410
2 Maciej Los 2,832
3 Abhinav S 2,732
4 Peter Leow 2,694


Advertise | Privacy | Mobile
Web01 | 2.8.150414.1 | Last Updated 14 Feb 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100