Click here to Skip to main content
15,887,485 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
`i want a query in which if and else will use but i do not know how it will use,below is my table structure ,i want result below mentioned after Produce table ,,please help thanks....`
 

>Item Master Table

`item_code	 Item_Name 	 Weight   	UOM 
  1001	       Pen	      44	   unit 
  1002       Computer     42	   unit`
 

Customer Table

` Customer_ID	 Customer_Name	 Contact	Address
     1	           Akhter	      3434  	 3434
     2	           Hussain   	  333	     555`
 
Customer Item Table
 

`Customer_ItemCode	 Customer_ItemName	 Item_code(FK)	Weight 	Customer_ID(FK) 
 2001	                 Pen America	      1	          100	    1`
 
SalesOrder Table
 
` Order_No	 Customer_ID (FK)	Order_Ref	Date 	 
     1           1                 333  	 333	 
     2        	 2	               222	     222`
 
 
 Produce table 
 
` Prod_No Item_Code(FK)	 qty	Order_No (FK)
   10001	 1	          1	        1	 
   10002	 2	          1      	 2	` 
 
when select 10001 record from Produce table then it result like
`(10001,Pen America,1)`
when i select record 10002 then it result like 
`(10002,Computer,1)`
 
Please suggest...thanks 


What I have tried:

DECLARE @CustID  as varchar
  select * INTO #tmp55 from SalesOrder where CustomerID IN (select CustomerID from CustomerItem)
  
  select @CustID = CustomerID from #tmp
  		
  
  if @CustID != ''
		select  Customeritem.CIName,Probale.Prdno,ItemMasterFile.BaleSize  from CustomerItem inner join ItemMasterFile on
		ItemMasterFile.Codeitem=CustomerItem.CItem inner join Probale on Probale.Codeitem=ItemMasterFile.CodeItem where Probale.Prdno=1000003
   
   
  else 
select  Probale.Prdno,ItemMasterFile.BaleSize,ItemMasterFile.BaleSize  from ItemMasterFile
		 inner join Probale on Probale.Codeitem=ItemMasterFile.CodeItem where Probale.Prdno=1000003
Posted
Updated 22-Apr-19 11:50am

1 solution

If you change your queries to ask what you want to ask, they will work. You've pasted the same query in to both conditions, so it will work the same.

Also, you're creating a temporary table called #tmp55 but reading from #tmp. Instead of trying random things, start from the start and work through. If you want to work with the collection of customer ids from a temp table, join to that table to get a collection of results. Make each step work before starting on the next one
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900