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.
Author |
Topic |
drdre
Starting Member
3 Posts |
Posted - 2011-03-15 : 15:55:12
|
hi all,I have been out of the programming field for years and only recently i have started using sql and so forth. after a few days of reading and stuff i was able to get a sql query that i needed to work:WITH Ranked ( Itemcode, rnk, ItemDesc ) AS ( SELECT Itemcode, ROW_NUMBER() OVER( PARTITION BY Itemcode ORDER BY Itemcode ), CAST( rssqldb.dbo.RSITEMDESCRIPTION.ItemDesc AS VARCHAR(8000) ) FROM rssqldb.dbo.RSITEM INNER JOIN rssqldb.dbo.RSITEMDESCRIPTION ON rssqldb.dbo.RSITEM.ItemID = rssqldb.dbo.RSITEMDESCRIPTION.ItemID INNER JOIN rssqldb.dbo.RSACCOUNT ON rssqldb.dbo.RSITEM.AccountID = rssqldb.dbo.RSACCOUNT.AccountIDWhere rssqldb.dbo.RSACCOUNT.AccountID=63And rssqldb.dbo.RSITEM.ObjectID=3), AnchorRanked ( Itemcode, rnk, ItemDesc ) AS ( SELECT Itemcode, rnk, ItemDesc FROM Ranked WHERE rnk = 1 ),RecurRanked ( Itemcode, rnk, ItemDesc ) AS ( SELECT Itemcode, rnk, ItemDesc FROM AnchorRanked UNION ALL SELECT Ranked.Itemcode, Ranked.rnk, RecurRanked.ItemDesc + ', ' + Ranked.ItemDesc FROM Ranked INNER JOIN RecurRanked ON Ranked.Itemcode = RecurRanked.Itemcode AND Ranked.rnk = RecurRanked.rnk + 1 )SELECT Itemcode, SUBSTRING(MAX( ItemDesc ), CHARINDEX('DOCUMENT',MAX( ItemDesc COLLATE Latin1_General_CS_AS)), CHARINDEX(' PROJECT',MAX( ItemDesc COLLATE Latin1_General_CS_AS))) FROM RecurRanked GROUP BY Itemcode;but now i realize that i want to pull(just to display the info) 2 more fields from the RSITEM table.. but i am really at a lost on where to them in.For example one of this fields is called AlternateCode..i am open to ideas.With Jah Jahanything is possible |
|
X002548
Not Just a Number
15586 Posts |
|
drdre
Starting Member
3 Posts |
Posted - 2011-03-15 : 18:17:18
|
Yeah i jumped into CTEs..I started off with a small query... did some reading online and asked one or 2 of my friends some questions and got this far..Didnt even know that CTE was a phrase till i was half way through that complex monster.Basically we use an application at my office that users multiple lines to hold data for items that we scanned.. I have no idea why they did that.. but thats how it was setup.. took me 3 or more days of research and testing to get that query to function with many cups of coffee and alot of fowl words being through at my pc..I am always open to ideas.. at present my base population of my db is over 150 items.. but i am working on itWith Jah Jahanything is possible |
 |
|
|
|
|
|
|