Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 Making the execution of a query optional
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Starting Member

1 Posts

Posted - 01/31/2014 :  00:29:41  Show Profile  Reply with Quote
Hello all,

I am using sql server management studio 2012. Please tae a minute or two to understand this problem, It's really important:(
The scenario is :
I have three table, Patient, patientAccount and Message.
Now, I am inserting values into tables Patient and Message first, and then after some time I am inserting values into PatientAccount Table.Now, the problem is in the software i am using sql with) i had this query:

select * from Patient join Message on Patient.GUID = Message.PatientGUID where Message.GUID = "..Data

and if I add PatientAccount in this query as well, like

select * from Patient join Message on Patient.GUID = Message.PatientGUID, PatientAccount where Message.GUID = "..Data

It becomes mandatory to add values to the PatientAccount table at the same moment when I am adding them to Patient and Message table, but what I really want is values to be taken up by query if there is data in the PatientAccount table, and if there is no values inserted into patientAccount table, It should pick up values from Patient and Message table only.
and I want all of it in one query.

Please please please help :(


Very Important crosS Applying yaK Herder

52326 Posts

Posted - 01/31/2014 :  07:40:32  Show Profile  Reply with Quote
sorry didnt understand the problem. do you mean first check for some values in pateintaccount and if not present take from other tables?
what all will be the input from user?

SQL Server MVP
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.02 seconds. Powered By: Snitz Forums 2000