Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

sql sales Expand / Collapse
Author
Message
Posted Wednesday, July 3, 2013 2:08 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Monday, July 29, 2013 2:56 AM
Points: 16, Visits: 20
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')
Post #1469896
Posted Wednesday, July 3, 2013 3:23 AM


Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Today @ 5:06 AM
Points: 3,013, Visits: 3,211
Is this homework or a real life problem?



-------------------------------
Posting Data Etiquette - Jeff Moden
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
Post #1469932
Posted Wednesday, July 3, 2013 4:51 AM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Friday, July 25, 2014 12:34 AM
Points: 1,888, Visits: 2,326
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/
Post #1469988
Posted Wednesday, July 3, 2013 5:13 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Friday, July 4, 2014 3:55 AM
Points: 2,836, Visits: 5,062
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!"
(So many miracle inventions provided by MS to us...)

How to post your question to get the best and quick help
Post #1469998
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse