sql sales

  • Write a SQL statement that will return all the Sales Orders for the Salespersons’ with the name starting with ‘John’.

    i have tried this :

    CREATE VIEW [dbo].[SalesOrder]

    AS

    SELECT dbo.Trnasction.Salesorder, dbo.SalesPerson.SalesPersonName

    FROM dbo.Trnasction CROSS JOIN

    dbo.SalesPerson

    WHERE (dbo.SalesPerson.SalesPersonName = N'John')

  • Is this homework or a real life problem?

    -------------------------------Posting Data Etiquette - Jeff Moden [/url]Smart way to ask a question
    There are naive questions, tedious questions, ill-phrased questions, questions put after inadequate self-criticism. But every question is a cry to understand (the world). There is no such thing as a dumb question. ― Carl Sagan
    I would never join a club that would allow me as a member - Groucho Marx

  • You can use LIKE keyword for this-

    SELECT dbo.Trnasction.Salesorder, dbo.SalesPerson.SalesPersonName

    FROM dbo.Trnasction CROSS JOIN

    dbo.SalesPerson

    WHERE dbo.SalesPerson.SalesPersonName LIKE 'John%'

    _______________________________________________________________
    To get quick answer follow this link:
    http://www.sqlservercentral.com/articles/Best+Practices/61537/

  • kapil_kk (7/3/2013)


    You can use LIKE keyword for this-

    SELECT dbo.Trnasction.Salesorder, dbo.SalesPerson.SalesPersonName

    FROM dbo.Trnasction CROSS JOIN

    dbo.SalesPerson

    WHERE dbo.SalesPerson.SalesPersonName LIKE 'John%'

    Looks good! But...

    The above will return every possible transaction for the every sales person named John%, including transaction which has nothing to do with this sales persons.

    CROSS JOIN is a bad choice for this sort of thing.

    It should be more like:

    SELECT dbo.SalesPerson.SalesPersonName, dbo.Trnasction.Salesorder

    FROM dbo.SalesPerson

    INNER JOIN dbo.Transction ON [Relevant Keys]

    WHERE dbo.SalesPerson.SalesPersonName LIKE 'John%'[/quote]

    _____________________________________________
    "The only true wisdom is in knowing you know nothing"
    "O skol'ko nam otkrytiy chudnyh prevnosit microsofta duh!":-D
    (So many miracle inventions provided by MS to us...)

    How to post your question to get the best and quick help[/url]

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply