Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Sql Server issues

Author  Topic 

Bright
Starting Member

4 Posts

Posted - 2015-01-14 : 03:21:17
I need to understand if someone faced any issues related to working on SQL or what are the interesting or challenging issues that are faced. And how one was able to resolve it. Please if anyone can let me understand so that it will be helpful not only in knowledge but also in interview point of view too.

Thnks

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2015-01-14 : 12:01:18
I face interesting and challenging issues everyday, so you'll need to be more specific.

Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

Bright
Starting Member

4 Posts

Posted - 2015-01-14 : 15:22:13
I have this stored Pro., for example..Besides lack of documentation to explain what it does.My challenge is to explain what else is complex about it.I have no work experience, and I am learning how to write a Complex stored procedure & to be able to explain it.



create procedure Whileloopexample
@Territoryname VARCHAR( 100)
AS
bEGIN
SET NOCOUNT ON
select Distinct YEAR(OrderDate) as Orderyear into #SalesYears FROM SALES.SalesOrderHeader
Order by Year(Orderdate) asc
Declare @Year int
set @Year=(SELECT TOP 1 OrderYear
FROM #SalesYears)


Create table #Result1 (Productname varchar(200),Total money,TerritoryName varchar(100),[Year] int)
while @year is not null
BEGIN
Insert into #Result1 (Productname, Total, TerritoryName,[year])
Select Top 5 d.Name as Productname,sum(a.LineTotal)as Total,c.Name as TerritoryName,
year(b.Orderdate) as [Year]
from Sales.SalesOrderDetail a
inner join Sales.SalesOrderHeader b on a.SalesOrderID=b.SalesOrderID
INNER JOIN Production.Product d ON a.ProductID = d.ProductID
Inner join Sales.SalesTerritory c on b.TerritoryID=c.TerritoryID
Where Year(b.OrderDate)= @year and c.Name = @Territoryname
group by d.Name,c.Name,b.Orderdate
order by SUM(LineTotal) desc

Delete from #SalesYears WHERE [Orderyear] = @Year
set @Year= ( Select Top 1 orderyear from #SalesYears)
END
SELECT * FROM #Result1
END

exec Whileloopexample 'Northwest'
Go to Top of Page
   

- Advertisement -