Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 9th, 2007, 04:14 PM
Authorized User
 
Join Date: Oct 2007
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default QUERY EXECUTION based on IF condition

HI,

I am trying to display records from more than one table depending on the condition How many tables the user chooses to display. I have several tables like contact_info, daily_nav,daily_returns and so on.
I have a check box for each table. IF user checks more than one table then the query should display records from all the table selected by the user. I am not getting how to write such query so I have started by writting the query with two fixe dtable which is as follows

CREATE PROCEDURE dbo.SearchDynamicData
(@v_Table1 int = NULL, @v_Table2 int = NULL, @v_FundName nvarchar(200))
AS
SET NOCOUNT OFF
IF @v_Table1 IS NOT NULL
BEGIN
 SELECT * FROM contact_info ,Fund_hrd WHERE
  contact_info.icdi_no LIKE Fund_hrd.icdi_no
  AND Fund_hrd.fund_name LIKE @v_FundName
END

SET NOCOUNT ON
GO
 Above code is for when table it works fine but how do I combine it with the second table say daily_nav
IF @v_Table2 IS NOT NULL

BEGIN
    SELECT * FROM daily_nav ,Fund_hrd WHERE
    daily_nav.icdi_no LIKE Fund_hrd.icdi_no
    AND Fund_hrd.fund_name LIKE @v_FundName
END


I don't know how to combine these statements. I tried using JOIN clause but it didnt work. Can anyone help me out with this?

Thanks



durgesh
__________________
durgesh





Similar Threads
Thread Thread Starter Forum Replies Last Post
Excluding Elements based on a Predicate Condition tasmisr XSLT 3 February 27th, 2008 01:00 PM
Pls help - Sorting based on condition kalwinhobbess Crystal Reports 0 September 10th, 2007 10:47 AM
Count nodes based of if condition suri_1811 XSLT 1 December 7th, 2006 08:00 PM
Question about counting records based on condition TheBlueSky Crystal Reports 1 May 31st, 2006 03:35 AM
popup based on condition msrnivas General .NET 0 July 11th, 2005 05:52 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.