Click here to Skip to main content
15,905,322 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
hi,
i have two tables and i write this query..
it successfully worked but only when
partner_master have a regid value
.
and i want that
if partner_master table has not regisd then only register_master display its record
if partner_master have regid value then both tables value display.

-----------
how to write dynamic query ??
------------
two tables
===========
1) register_master
2) partner_master
------------------------------
SQL
@param varhcar(100)=null,
@regid bigint=0,
@sql_query varchar(max)=null

if @param='profile_detail'
    begin
        select * from Register_Master join Partner_Master
        on Register_Master.Reg_Id=Partner_Master.Reg_Id
        where
        Register_Master.Reg_Id=@regid;
    end

-----------
write dynamic query in @sql_query parameter.
-------------------------------
Posted

1 solution

Try LEFT JOIN
SQL
select * from Register_Master LEFT JOIN Partner_Master
on Register_Master.Reg_Id=Partner_Master.Reg_Id
where
Register_Master.Reg_Id=@regid

Find out more on Visual Representation of SQL Joins[^]
 
Share this answer
 
v2
Comments
Manish Dalwadi 9-Mar-14 4:05am    
hey dr...
thank you thank you so so so much..
Peter Leow 9-Mar-14 4:11am    
You are welcome, do accept the solution and vote.
Wonder why it was voted down?

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900