Click here to Skip to main content
15,905,323 members
Home / Discussions / Database
   

Database

 
AnswerRe: what version of MS SQL I should buy Pin
vaghelabhavesh12-Feb-09 6:26
vaghelabhavesh12-Feb-09 6:26 
Questionhow to search amharic unicode data from sql server? Pin
abiniyam12-Feb-09 2:26
abiniyam12-Feb-09 2:26 
AnswerRe: how to search amharic unicode data from sql server? Pin
Wendelius12-Feb-09 3:03
mentorWendelius12-Feb-09 3:03 
QuestionCan i insert "Dec-08" in Sql server 2005 database table column having Datatype "DateTime" Pin
Dattatraya K12-Feb-09 2:09
Dattatraya K12-Feb-09 2:09 
AnswerRe: Can i insert "Dec-08" in Sql server 2005 database table column having Datatype "DateTime" Pin
Wendelius12-Feb-09 3:00
mentorWendelius12-Feb-09 3:00 
GeneralRe: Can i insert "Dec-08" in Sql server 2005 database table column having Datatype "DateTime" Pin
Dattatraya K12-Feb-09 3:05
Dattatraya K12-Feb-09 3:05 
GeneralRe: Can i insert "Dec-08" in Sql server 2005 database table column having Datatype "DateTime" Pin
Wendelius12-Feb-09 4:07
mentorWendelius12-Feb-09 4:07 
QuestionHelp with a very complex query Pin
www.Developerof.NET12-Feb-09 0:54
www.Developerof.NET12-Feb-09 0:54 
Hi all,

I am being struglling with a query from past 2-3 days and i m unable to find a solution to it.
I am using sql 2000 and i am having the foll probs.

I have a table "FG_STK" which stores the stock of all items branch wise. The schema is

FG_ID,BranchID,Item_Code,Item_Batch_No,Item_Lot_No,Recon_Code,CLD_Qty,Sku_Qty

and other table called Recon_Codes which has foll schema..

Recon_Code,Recon_Type,Recon_Description
which has predefined values such as
100 CR Opening Stock
200 DR Stock Removed
8000 DR Damage Material Transfer
9000 DR Expired Material Transfer


and in FG_STK the data stored as
1, 2001,350154,Mar809,Mar1208,100,100,0
(item 350154 at branch 2001 with batch Mar809 and Lot Mar1208 with Opening stock of 100 Clds)
2,2002,350154,Feb0809,Feb1208,8000,0,200
(item 350154 with loose qty 200 at branch 2002 with batch Feb0809 and Lot Feb1208 is removed for the purpose of transfer because its damaged)

The rows in FG_STk with recon code not starting with 8 and 9 are considered as good stock, while rows with recon code starting with 8 are considered as damaged and with 9 are considered as expired.

Now to fetch good clds i did the following


Select item.Brand,item.Category,item.Item_Desc as Item,stock_data.batchno,stock_data.lotno,isnull((SUM(CR) - SUM(DR)),0) as Total_Clds,isnull((SUM(CRSKU)-SUM(DRSKU)),0) AS Tot_Sku

From(
SELECT Case Recon_Type
When 'CR' Then SUM(CLD_Qty)
When 'DR' Then 0 END CR,
Case Recon_Type
When 'CR' Then 0
When 'DR' Then SUM(CLD_Qty) END DR,
Case Recon_Type
When 'CR' Then SUM(Sku_Qty)
When 'DR' Then 0 END CRSKU,
Case Recon_Type
When 'CR' Then 0
When 'DR' Then SUM(Sku_Qty) END DRSKU,Item_Code,Item_Batch_No as batchno,Item_Lot_No as lotno
FROM FG_STK INNER JOIN Recon_Codes ON FG_STK.Recon_Code = Recon_Type.Recon_Code
where BranchID=@branch_ID

GROUP BY Recon_Type,Item_Code ,Item_Batch_No,Item_Lot_No
)stock_data
inner join
view_Full_Item_Details item
on
stock_data.Item_Code=item.code
group by stock_data.Item_Code,Item_Desc,stock_data.batchno,stock_data.lotno,item.Brand,item.Category
having ((SUM(CR) - SUM(DR))<>0 or (SUM(CRSKU)-SUM(DRSKU))<>0)

Now the problem is i want damaged and expired along with good stock in diff columns which has almost the same query with an additional where clause as
and Recon_Codes.Recon_Code like '8%' for damaged

and

and Recon_Codes.Recon_Code like '9%' for expired

and i want to show data as

Brand, Category, Item,Batch_no,Lot_no,Good_Cld,Good_Loose,Damaged_Cld,Damaged_Loose,Expired_CLD,Expired_Loose

also if the batch and lot of good cld, expired cld and damaged cld are same they should appear in same row else in diff row.

Any help would be kindly appreciated.

When you fail to plan, you are planning to fail.

AnswerRe: Help with a very complex query Pin
Wendelius12-Feb-09 4:28
mentorWendelius12-Feb-09 4:28 
QuestionAdd 100 in null Pin
.NET- India 11-Feb-09 21:59
.NET- India 11-Feb-09 21:59 
AnswerRe: Add 100 in null Pin
Wendelius11-Feb-09 22:22
mentorWendelius11-Feb-09 22:22 
AnswerRe: Add 100 in null Pin
Rob Philpott11-Feb-09 22:22
Rob Philpott11-Feb-09 22:22 
QuestionSql Reporting services Pin
member2711-Feb-09 20:54
member2711-Feb-09 20:54 
AnswerRe: Sql Reporting services Pin
Wendelius11-Feb-09 20:59
mentorWendelius11-Feb-09 20:59 
GeneralRe: Sql Reporting services Pin
member2712-Feb-09 0:44
member2712-Feb-09 0:44 
GeneralRe: Sql Reporting services Pin
Wendelius12-Feb-09 4:53
mentorWendelius12-Feb-09 4:53 
QuestionRegarding StoredProcedure Pin
chinni111-Feb-09 19:33
chinni111-Feb-09 19:33 
AnswerRe: Regarding StoredProcedure Pin
Wendelius11-Feb-09 20:00
mentorWendelius11-Feb-09 20:00 
QuestionSQL server 2008 Pin
NidhiKanu11-Feb-09 19:28
professionalNidhiKanu11-Feb-09 19:28 
AnswerRe: SQL server 2008 Pin
Wendelius11-Feb-09 19:58
mentorWendelius11-Feb-09 19:58 
GeneralRe: SQL server 2008 Pin
NidhiKanu11-Feb-09 20:06
professionalNidhiKanu11-Feb-09 20:06 
GeneralRe: SQL server 2008 Pin
Wendelius11-Feb-09 20:12
mentorWendelius11-Feb-09 20:12 
GeneralRe: SQL server 2008 Pin
NidhiKanu11-Feb-09 20:19
professionalNidhiKanu11-Feb-09 20:19 
GeneralRe: SQL server 2008 Pin
Wendelius11-Feb-09 20:37
mentorWendelius11-Feb-09 20:37 
QuestionMSSQL how do I get the schema setup Pin
alex.barylski11-Feb-09 14:26
alex.barylski11-Feb-09 14:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.