July 3, 2013 at 2:08 am
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')
July 3, 2013 at 3:23 am
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
July 3, 2013 at 4:51 am
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/
July 3, 2013 at 5:13 am
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]
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply