Learn SQL Server 2008

SQL Server Learning Joes 2 Pros Series

All Five Books in a Combo (30% Discount)
[Amazon] | [Flipkart] | [IndiaPlaza]

Beginning SQL Joes 2 Pros (vol 1)
[Amazon] | [Flipkart] | [Kindle] | [IndiaPlaza]

SQL Queries Joes 2 Pros (vol 2)
[Amazon] | [Flipkart] | [Kindle] | [IndiaPlaza]

SQL Architecture Basics Joes 2 Pros (vol 3)
[Amazon] | [Flipkart] | [Kindle] | [IndiaPlaza]

SQL Programming Joes 2 Pros (vol 4)
[Amazon] | [Flipkart] | [Kindle] | [IndiaPlaza]

SQL Interoperability Joes 2 Pros (vol 5)
[Amazon] | [Flipkart] | [Kindle] | [IndiaPlaza]

About these ads

3 thoughts on “Learn SQL Server 2008

  1. Hi Everyone,
    what I want is to write a query which will fetch me 3 column:-

    nvarchar column1
    interger Values column2
    single cell of the summed column2

    is it possible , I am getting the following error:-

    Msg 8120, Level 16, State 1, Line 1 Column ‘tablename.columnname’ is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.

    What is the correct procedure to get data in the format I wish to get.

    Edit

    Jaques’ answer works but I dont get what I want. What I want is:

    column 1 PID | column 2 SID | column 3 | column 4 | Column 5(Total of 4)
    ————————————————————————-
    1 | 1 | ABC | 125.00 | 985.00
    2 | 2 | XYZ | 420.00 |
    3 | 3 | DEF | 230.00 |
    4 | 4 | GHI | 210.00 |

    I am unable to construct a query for it. But I do know its like associating a single row as to a set of rows. Here’s the whole scenario :- I have table with columns 1,2,3,4 , I have to get a column of date from a different table on the left and a column total on the right. The target is to get a heading like – Date, ABC,XYZ,DEF,GHI,Total. The columns names ABC,XYZ,DEF and GHI are rows in a different table . Please provide a solution.

  2. I’m facing a problem I want result like this please help me
    I’m able to count the number of employees in a department but I can’t show as I want
    Thanks in advance
    Tbl_Dept
    Dept_ID Dept_Name
    1 .NET
    2 Java
    3 Php
    Tbl_Emp
    Emp_ID Dept_ID Emp_Name
    1 1 Ram
    2 2 Mohan
    3 3 Sohan
    4 2 Reeta
    5 3 Sonu
    6 1 Karan
    Result
    Dept_Name Employees
    .NET Ram,Karan
    Java Mohan,Reeta
    Php Sohan,Sonu

  3. if I am correct, you want to display all Name and Dept of All Employee.

    Select d.Dept_Name, e.Emp_Name
    from Tbl_Dept d, Tbl_Emp e
    where d.Dept_ID = e.Dept_ID
    Order by d.Dept_ID asc

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s