Click here to Skip to main content
15,891,754 members
Home / Discussions / Database
   

Database

 
AnswerRe: SQL Query - write all in one query Pin
PIEBALDconsult1-Aug-12 8:42
mvePIEBALDconsult1-Aug-12 8:42 
GeneralRe: SQL Query - write all in one query Pin
Raman samineni1-Aug-12 16:02
Raman samineni1-Aug-12 16:02 
GeneralRe: SQL Query - write all in one query Pin
PIEBALDconsult1-Aug-12 18:23
mvePIEBALDconsult1-Aug-12 18:23 
AnswerRe: SQL Query - write all in one query Pin
Mycroft Holmes1-Aug-12 13:17
professionalMycroft Holmes1-Aug-12 13:17 
GeneralRe: SQL Query - write all in one query Pin
Raman samineni1-Aug-12 15:56
Raman samineni1-Aug-12 15:56 
GeneralRe: SQL Query - write all in one query Pin
Mycroft Holmes1-Aug-12 16:25
professionalMycroft Holmes1-Aug-12 16:25 
GeneralRe: SQL Query - write all in one query Pin
Raman samineni2-Aug-12 8:22
Raman samineni2-Aug-12 8:22 
AnswerRe: SQL Query - write all in one query Pin
Eddy Vluggen1-Aug-12 22:34
professionalEddy Vluggen1-Aug-12 22:34 
Raman samineni wrote:
I need to write all in one query

What would you gain from having it in a single statement? As PIEBALD stated, you can put them in a single SqlCommand and execute them.

  • The first Sql-statement will not work. Test it again, it lacks a FROM clause.
  • you could embed the count as a sub-select, like this;
    SQL
    SELECT E.FirstName +' ' + E.LastName AS Agent
          ,(SELECT COUNT(*) FROM CGCSLF WHERE Dispo = 'Comp') AS [Comp]
     FROM [cgs].dbo.Employ E with (NoLock)
    WHERE E.EmploId = 2305
    

  • What the ELEPHANT is that NOLOCK doing there??
  • You need to pay attention to your formatting
  • EmploId is redundant; you're already in the "E" table, just name the damn thing "Id". That way all keys are named Id, saves some time typing and thinking, less chances on a typo, and a lot clearer when reading the code.

Bastard Programmer from Hell Suspicious | :suss:
if you can't read my code, try converting it here[^]

GeneralRe: SQL Query - write all in one query Pin
Raman samineni2-Aug-12 8:19
Raman samineni2-Aug-12 8:19 
GeneralRe: SQL Query - write all in one query Pin
Eddy Vluggen2-Aug-12 8:59
professionalEddy Vluggen2-Aug-12 8:59 
GeneralRe: SQL Query - write all in one query Pin
Raman samineni6-Aug-12 8:37
Raman samineni6-Aug-12 8:37 
GeneralRe: SQL Query - write all in one query Pin
Raman samineni6-Aug-12 8:39
Raman samineni6-Aug-12 8:39 
QuestionRe: SQL Query - write all in one query Pin
Eddy Vluggen6-Aug-12 8:50
professionalEddy Vluggen6-Aug-12 8:50 
AnswerRe: SQL Query - write all in one query Pin
Raman samineni6-Aug-12 11:11
Raman samineni6-Aug-12 11:11 
RantRe: SQL Query - write all in one query Pin
Eddy Vluggen6-Aug-12 11:30
professionalEddy Vluggen6-Aug-12 11:30 
GeneralRe: SQL Query - write all in one query Pin
Raman samineni8-Aug-12 5:30
Raman samineni8-Aug-12 5:30 
GeneralRe: SQL Query - write all in one query Pin
Eddy Vluggen8-Aug-12 7:00
professionalEddy Vluggen8-Aug-12 7:00 
GeneralRe: SQL Query - write all in one query Pin
Raman samineni8-Aug-12 11:21
Raman samineni8-Aug-12 11:21 
GeneralRe: SQL Query - write all in one query Pin
Eddy Vluggen8-Aug-12 12:12
professionalEddy Vluggen8-Aug-12 12:12 
QuestionSSRS Pin
Arul R Ece31-Jul-12 23:57
Arul R Ece31-Jul-12 23:57 
AnswerRe: SSRS Pin
Eddy Vluggen1-Aug-12 2:48
professionalEddy Vluggen1-Aug-12 2:48 
QuestionReplication Help Pin
Mohamad Shahmardan31-Jul-12 23:09
Mohamad Shahmardan31-Jul-12 23:09 
AnswerRe: Replication Help Pin
Eddy Vluggen1-Aug-12 0:51
professionalEddy Vluggen1-Aug-12 0:51 
GeneralRe: Replication Help Pin
Mohamad Shahmardan1-Aug-12 5:48
Mohamad Shahmardan1-Aug-12 5:48 
GeneralRe: Replication Help Pin
Pete O'Hanlon1-Aug-12 6:03
mvePete O'Hanlon1-Aug-12 6:03 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.