[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

if statments

Posted on 2012-03-23
1
Medium Priority
?
299 Views
Last Modified: 2012-03-27
if
(
select distinct left(bill_id,2) from openquery(PP_NEW,
'select distinct s.sku_no,l.item_no,s.bill_id,i.ship_dt,i.po_no
from invoice as i  left outer join line_it as l
on i.invoice_no=l.invoice_no
left outer join sku as s
on i.ship_id=s.bill_id and
l.item_no=s.item_no
where i.ship_dt>={04/01/12} and
i.bill_id=[CWALMF] and
s.type=[S]
')
where ship_dt='2012-04-01'
and po_no in ('7953090880','7953090866')
)
='WM'

begin

select distinct bill_id from openquery(PP_NEW,
'select bill_id
from sku
where left(bill_id,2)=[WM]
')

end

else

begin

select distinct bill_id from openquery(PP_NEW,
'select bill_id
from sku
where bill_id=[CWALMF]
')
End


WM02795
WM03219
WM02564
WM01525
WM05488
WM02808
WM01969


I need the query to go through the data returned from the query of the if statment and evaluate if the result for ‘WM’ is TRUE to run one query and if it is FALSE to run a different query, the problem with this structure is that  I do not get the else also one po_no will return TRUE for left(bill_id,2)=’WM’ and the other will return FALSE
And I only get in the result set the first query

select distinct bill_id from openquery(PP_NEW,
'select bill_id
from sku
where left(bill_id,2)=[WM]

and  I expect to get information for the second query too.
0
Comment
Question by:GadFriedman
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 12

Accepted Solution

by:
sachitjain earned 2000 total points
ID: 37760636
Does it help you?

declare @po_no_tbl table (SNo int identity(1,1), po_no varchar(12))
declare @bill_no_tbl table (bill_id varchar(12))

insert into @po_no_tbl (po_no) values ('7953090880')
insert into @po_no_tbl (po_no) values ('7953090866')

declare @i int, @cnt int, @po_no varchar(12)
set @i = 1
select @cnt = COUNT(SNo) from @po_no_tbl

while @i <= @cnt
begin
      select @po_no = po_no from @po_no_tbl where SNo = @i
      if
      (
            select distinct left(bill_id,2) from openquery(PP_NEW,
            'select distinct s.sku_no,l.item_no,s.bill_id,i.ship_dt,i.po_no
            from invoice as i  left outer join line_it as l
            on i.invoice_no=l.invoice_no
            left outer join sku as s
            on i.ship_id=s.bill_id and
            l.item_no=s.item_no
            where i.ship_dt>={04/01/12} and
            i.bill_id=[CWALMF] and
            s.type=[S]
            ')
            where ship_dt='2012-04-01'
            and po_no  = @po_no
      ) ='WM'
      begin
            insert into @bill_no_tbl (bill_no)
            select distinct bill_id from openquery(PP_NEW,
            'select bill_id
            from sku
            where left(bill_id,2)=[WM]
            ')
      end
      else
      begin
            insert into @bill_no_tbl (bill_no)
            select distinct bill_id from openquery(PP_NEW,
            'select bill_id
            from sku
            where bill_id=[CWALMF]
            ')
      End
      set @i = @i + 1
end
select * from @bill_no_tbl
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I am showing a way to read/import the excel data in table using SQL server 2005... Suppose there is an Excel file "Book1" at location "C:\temp" with column "First Name" and "Last Name". Now to import this Excel data into the table, we will use…
When writing XML code a very difficult part is when we like to remove all the elements or attributes from the XML that have no data. I would like to share a set of recursive MSSQL stored procedures that I have made to remove those elements from …
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question