I have 1 column in a table with value like below:
Activation period=0#Actual pay channel=214952491#Agreement id=1115151#Alternative charge code description=Fido Internet 75 - illimité
#Alternative packaging code description= #Alternative saving code description=Offre Fido Internet#Apply additional discount=N
#BCB ind=N#BCB seq no=0#Base charge amount=57.00000#Base offer ID=505613187#Base offer instance ID=5194671#Base offer item ID=505613107
#Bill frequency=1#Bulk billing code=Permanent#Business entity=0#Charge description=Fido Internet 75 - Unlimited#Charge identifier=D
#Charge nullify by discount ind=Y#Charge type=DSC#Check restriction ind=N#Commercial or residential=Residential#Commission id=006020
#Commitment end date=#Commitment period=#Commitment start date=#Component code=HS#Contract code=0#Contract desc code= #Contract dummy RC ind=N
#Contract revenue type=RC#CurrentCycleEndDate=00000000#CurrentCycleStartDate=00000000#Customer sub type=R#Customer type=F#Dealer code=CC
#Discount item ID=505613217#Discount type=NONE#Display charge ind= #Dummy ind=N#Dummy quotation ind=N#Dwelling code=07
#Equipment serial number= #Foreign manufacturer= #Foreign model= #Franchise=RCM#Included ind=N#LPIF indicator=N#Line of business=Internet
#Map area= #Multi dweling/single unit=MDU#Notification indicator=Y#Number of occurences=0#Occurrence in order=0#Offer connect Date=20180403
#Offer name=HS Fido Internet Embedded Discount 2018 - 3MF discount HS ACQ CON#Order id=10173580#Orig charge ind=N#Orig charge seq no=0
#Orig discount amount=0#Original charge amount=-57.00000#Original commitment start date=20201231#Override RC indicator=N#Override policy=N
#PRIT name=HS Fido Internet Embedded Discount 2018 - 3MF discount HS ACQ CON - RC Discount#Packaging code= #Packaging description= #Period scale=0
#Printing charge ind= #Product offer ID=505618817#Promotion effective date=20180403#Promotion expiration date=20180703#Promotion indicator=Y
#Quantity=1#RC expiration date=20180704#Rate=-57.00000#Rate area=RCM#Relation type= #Retrieve exemption=Y#SAM key=2330000367541#Sales channel=
#Savings code=SC_CM_R_G9CSSSS#Savings description=Fido Internet Offer#Scale type=D#Service province=ON#Subscriber status=A#Subscriber sub type=Z
#Subscriber type=HS#Taxable amount=-57.00000#Waive ind= #
Here, i need to update "Promotion expiration date" value with the new one. How can i do it using update command.
Please help me with the command how to achieve this result?
Thanks
I prefer using simple string functions like INSTR, SUBSTR and REPLACE, but in this case it is much more readable with a simple REGEXP-REPLACE:
with testtab as(
select '[...]#Product offer ID=505618817#Promotion effective date=20180403#Promotion expiration date=20180703#Promotion indicator=Y
#[...]#Waive ind= #' as text from dual)
select regexp_replace(text, 'Promotion expiration date=\d*', 'Promotion expiration date=' || to_char(sysdate, 'YYYYMMDD') ) from testtab;
\d* is a 0 to infinite amout of numbers like '', 345345 or 4356456345634563546. It matches untill the #. This means that it replaces Promotion expiration date=20180606 as well as Promotion expiration date=345665756567
Related
OK, I'm quite new to SQL and didn't get to much training!
I'm using SSMS to create stored procedures and open them in Excel.
The code below work just fine, but I need to add a drill down to get more info on some lines.
We need to follow what was invoice and paid on a batch of contracts for our project. Each contract have multiple lines with a description and a couple of other fields(reference, line #, G/L # etc). Plus we have the value of the line, the amount that was invoice for this line and the amount that was paid.
Main table 'CSCOMVTL' have the basic infos including the base value and the invoice amount, but not the paid amount.
'JRAPRVTL' is the list of all invoices with; invoice no., invoice date, invoiced amount and paid amount that we may need to see.
So for each base line, we need a +/- button to show/hide details of the invoice.
Invoice amount and paid amount could be from a rollup, but the number and date won't be on the parent line. If they could be in the same column as other field not needed it would be great, but I could live with 2 extra columns.
Thanks!
ALTER PROCEDURE [dbo].[marpt_qmd_AccPmt_DetailsST]
#contrat varchar(30), #projet varchar(30)
AS
BEGIN
CREATE TABLE #RPT
(
Ligne INT,
Lien INT,
Act VARCHAR (10),
Descr VARCHAR (90),
MntBase DECIMAL (20,2),
MntFact DECIMAL (20,2),
Modif VARCHAR (40),
Descr3 VARCHAR (90),
Lien2 INT,
MntPy DECIMAL (20,2) default '0',
)
INSERT INTO #RPT (Ligne, Lien, Act, Descr, MntBase, MntFact)
SELECT ROW, DETAILCHANGEORDERCOU, ACTIVITY, DESCRIPTION, AMOUNT, INVOICE
FROM cscomvtl
WHERE PROJECTNUMBER = #projet
and LTRIM(RTRIM(PONUMBER)) = #contrat
UPDATE #RPT
SET Modif=m.CHANGEORDERNUMBER, Descr3=m.DESCRIPTION, Lien2=m.CHANGEORDERCOUNTER
FROM cscomac m, #RPT r
where m.COUNTER=r.Lien
UPDATE #RPT
SET MntPy=payment
FROM #RPT r, (select POLINE, sum(payment) payment from jraprvtl where PROJECTNO=#projet
and LTRIM(RTRIM(PURCHASEORDER))=#contrat group by POLINE) d
where r.Ligne=d. POLINE
SELECT
Ligne as 'Ligne',
Act as 'Act.',
Descr as 'Description 1',
MntBase as '$ Base',
MntFact as '$ Invoiced',
Modif as 'Num. Modif.',
Descr3 as 'Description 2',
MntPy as '$ Paid'
FROM #RPT
Order by Ligne
Drop table #RPT
First off, take the time & learn SQL. It's an invaluable tool in your toolkit!
Okay, enough of the lecture. In looking through your code, you don't seem to really need the temp table #rpt, you just need to understand JOINs. Hopefully this SQL will get you what you are looking for:
SELECT vtl.ROW AS Ligne, vtl.DETAILCHANGEORDERCOU AS Lein, vtl.ACTIVITY AS Act,
vtl.DESCRIPTION AS Descr, vtl.AMOUNT AS MntBase, vtl.INVOICE AS MntFact,
mac.CHANGEORDERNUMBER AS Modif, mac.DESCRIPTION AS Descr3, mac.CHANGEORDERCOUNTER AS Lien2,
sum(jrap.payment) AS MntPy
FROM cscomvtl AS vtl
LEFT OUTER JOIN cscomac AS mac
ON vtl.detailchangeordercou = mac.counter
LEFT OUTER JOIN jraprvtl AS jrap
ON vtl.row = jrap.poline
WHERE projectnumber = #projet AND LTRIM(RTRIM(ponumber)) = #contrat
GROUP BY vtl.row, vtl.detailchangeordercou, vtl.activity, vtl.description, vtl.amount,
vtl.invoice, mac.changeordernumber, mac.description, mac.changeordercounter
You will likely have to tweak it to fit what you're trying to do in Excel, since you really didn't give much to go on there.
I have a table Invoices with InvoiceNumber as varchar(32)
The customer can modify how will be their invoices format, like: INV00001, 000001, I00001, etc., so when it's configured, the program each time that is created a invoice it will increment the invoice number so it can be unique
I would like to search invoices but using integer values like from: 2 to 10, like this:
SELECT * FROM Invoices WHERE InvoiceNumber >= '2' AND InvoiceNumber <= '10'
How I can do that with a varchar field?
EDIT: Customer set the format like they want and most of them never change it, most of them use three chars and the rest numbers like: INV0000001
This is not my database, I'm just developing an addon for this app, can't change anything in the DB
InvoiceNumber
-------------
INV00260
INV00261
INV00262
INV00263
INV00264
INV00265
INV00266
INV00267
INV00268
A customer want to search invoice using a between values, let's say he wants to search invoice between INV00262 and INV00267, the customer wants to search by the number, the result should be:
INV00262
INV00263
INV00264
INV00265
INV00266
INV00267
But using integer values like: WHERE InvoiceNumber >= '262' AND InvoiceNumber <= '267'
Assuming that your InvoceNmber contains valid integer values just stored as string ..
You could cast as INT the string eg:
SELECT * FROM Invoices WHERE cast(InvoiceNumber AS INT)>= 2 AND InvoiceNumber <= 10
I believe a more effective use of indexes would work this way. Compare query plans with the accepted answer to see if there's a big difference.
select * from T
where InvoiceNumber between
'INV' + right('0000' + cast(<start> as varchar(5)) and
'INV' + right('0000' + cast( <end> as varchar(5));
It's also a bit simpler and the arguments only need to be referenced once which can make a difference in client code.
today i faced a rather weird problem while i was coding and i really have no idea how to fix this, this is the code i wrote
select kv.third_party, --THIRD PARTY CODE
kv.NUM_PUROR, --PURCHASE CODE
kv.DTACN_COD_ACN_DTACN --ACCOUNT CODE
SUM(DEBT) DEBT,
SUM(CREDIT) CREDIT
FROM(SELECT ACNVI.third_party,
ACNVI.NUM_PUROR,
ACNVI.DTACN_COD_ACN_DTACN
SUM(ACNVI.AMN_DBT_ACNVI - ACNVI.AMN_CRD_ACNVI) DEBT,
0 CREDIT
FROM BFS_ACCOUNT_COUVHER_ITEMS ACNVI
WHERE TO_CHAR(ACNVI.ACVOH_DAT_DCM_ACVOH,'YYYY') BETWEEN '1990' AND '2000'
AND SUBSTR(ACNVI.DTACN_COD_ACN_DTACN,1,4) IN ('3102')
GROUP BY ACNVI.third_party,
ACNVI.NUM_PUROR,
ACNVI.DTACN_COD_ACN_DTACN,
SUBSTR(ACNVI.DTACN_COD_ACN_DTACN,1,4)
HAVING SUM(ACNVI.AMN_DBT_ACNVI - ANCVI.AMN_CRD_ACNVI)>0
UNION
SELECT ACNVI.third_party,
ACNVI.NUM_PUROR,
ACNVI.DTACN_COD_ACN_DTACN
0 DEBT,
SUM(ACNVI.AMN_CRD_ACNVI- ACNVI.AMN_DBT_ACNVI ) CREDIT
FROM BFS_ACCOUNT_COUVHER_ITEMS ACNVI
WHERE TO_CHAR(ACNVI.ACVOH_DAT_DCM_ACVOH,'YYYY') BETWEEN '1990' AND '2000'
AND SUBSTR(ACNVI.DTACN_COD_ACN_DTACN,1,4) IN ('3102')
GROUP BY ACNVI.third_party,
ACNVI.NUM_PUROR,
ACNVI.DTACN_COD_ACN_DTACN,
SUBSTR(ACNVI.DTACN_COD_ACN_DTACN,1,4)
HAVING SUM(ACNVI.AMN_CRD_ACNVI- ACNVI.AMN_DBT_ACNVI)>0) KV
*****
GROUP BY KV.THIRD_PART,KV.NUM_PUROR,KV.DTACN_COD_ACN_DTACN
ok so the above is the code i wrote and what i want which i dunno how to do is this: i want to have something like below in the star area
"having sum(debt)=sum(credit)"
but when i write that the table will be empty.
parameter meanings:
#amn_dbt_acnvi --- amount of debt for each account
#amn_crd_acnvi --- amount of credit for each account
#(amn_dbt_acnvi-amn_crd_acnvi) --- account balance (i wrote two kinds in the code because i want to have one balance on debt and one balance on credit)
#bfs_account_voucher_items ---this is the table with required info (debt,credit,third_party code ,etc.)
needed result is something like this for example :
row#1 : third_party: a // num_puror: b//account_code: 310201//debt : 100 credit :0
row#2 : third_party: a // num_puror: b//account_code: 310203//debt : 0
credit:100
subtract of them should be 0
I'm trying to retrieve financials for firms listed at Tel Aviv Stock Exchange, e.g.: LUMI (Bank Leumi), by quantmod using source=yahoo.
Here is the error I get:
getFin("LUMI",src="yahoo")
Error in thead[x]:thead[x + 1] : NA/NaN argument
I also tried:
getFin("LUMI.TA",src="yahoo")
Error in thead[x]:thead[x + 1] : NA/NaN argument
It seems that getFin does not work for foreign firms, any lead?
First query: Check if the symbol you are searching in Google Finance has financials (as a link/tab) under the Company tab on the left.
getFin/getFinancials is essentially query searching for this through the API configuration.
Also, note that yahoo is overridden by google even after assigning src = "yahoo". Check ?getFin in the console to confirm. It says under the description in help: Download Income Statement, Balance Sheet, and Cash Flow Statements from Google Finance.
If the company's financial statements are not recorded under the U.S. Securities and Exchange Commission, check here: SEC: Enter Company Symbol under Fast Search to see if the European company has filings under the SEC.
For example NVS - Novartis works, unlike LUMI or Nestlé (NSRGY).
library(quantmod)
myData <- new.env()
class(myData)
ls(myData)
NVS <- getFinancials('NVS', env = myData, src = "yahoo", auto.assign=TRUE)
viewFinancials(NVS.f, type= 'IS', period = 'Q') #Options `type=c('BS','IS','CF'), period=c('A','Q')`
Output from: viewFinancials(NVS.f, type= 'IS', period = 'Q') (Truncated output data for view purposes).
> viewFinancials(NVS.f, type= 'IS', period = 'Q')
Quarterly Income Statement for NVS
2014-12-31 2014-09-30 2014-06-30
Revenue 13354.00 13300.00 26980.00
Other Revenue, Total NA NA NA
Total Revenue 13354.00 13300.00 26980.00
Cost of Revenue, Total 4416.00 4421.00 8508.00
Gross Profit 8938.00 8879.00 18472.00
Selling/General/Admin. Expenses, Total 3965.00 3565.00 7463.00
Research & Development 2537.00 2161.00 4388.00
You can get what you need off the BS, IS, or CF by doing the following:
> NVS_Q <- viewFinancials(NVS.f, type= 'IS', period = 'Q')
Quarterly Income Statement for NVS
> Revenue2014_12_31 <- NVS_Q[1,1]
> Revenue2014_12_31
[1] 13354
I have specified the Values in the Which Report Parameter
Label Value
Occupancy Occupancy
Pitch Nights Sold PitchNightsSold
Capacity Capacity
Pitch Nights Sold And Capacity PitchNightsSoldAndCapacity
Pitch Nights Sold And Occupancy PitchNightsSoldAndOccupancy
Pitch Nights Sold Capacity And Occupancy PitchNightsSoldCapacityAndOccupancy
Main Dataset:
SELECT
OccupancyDetail.CalendarYear,
OccupancyDetail.CalendarMonth,
SUM(OccupancyDetail.No_of_Nights) AS No_of_Nights,
SUM(OccupancyDetail.Capacity) AS Capacity
FROM
OccupancyDetail INNER JOIN
Site ON OccupancyDetail.Site_Skey = Site.Site_Skey
WHERE (OccupancyDetail.ReferenceDate = convert(Date,getdate()))
AND CASE WHEN #Time = 'YEAR' THEN CAST(CalendarYear as varchar(4)) else CalendarMonth + ' ' + CAST(CalendarYear as varchar(4)) end in (#Dates)
AND ((#ReportingLevel = 'BDM' AND Site.BDM in(#BDM_Region_Site))
OR (#ReportingLevel = 'Region' AND Site.Region in (#BDM_Region_Site))
OR (#ReportingLevel = 'SiteName' AND Site.SiteName in (#BDM_Region_Site)))
GROUP BY OccupancyDetail.ReferenceDate,OccupancyDetail.CalendarYear, OccupancyDetail.CalendarMonth
Time Dataset:
select
DateChoice
FROM
(
select distinct
CalendarYear,
1 as MonthNumber,
CAST(CalendarYear as varchar(4)) as DateChoice
from Time
where #Time = 'YEAR'
union all
select Distinct
CalendarYear,
MonthNumber,
CalendarMonth + ' ' + CAST(CalendarYear as varchar(4)) as DateChoice
from Time
where #Time = 'MONTH'
) as QRYDATA
ORDER BY CalendarYear,MonthNumber
Site Dataset:
SELECT DISTINCT BDM AS SiteInfo FROM Site
WHERE #ReportingLevel = 'BDM'
UNION ALL
SELECT DISTINCT Region FROM Site
WHERE #ReportingLevel = 'Region'
UNION ALL
SELECT DISTINCT SiteName FROM Site
WHERE #ReportingLevel = 'SiteName'
On Report Builder 3.0 I have created 6 reports that are hidden unless it is selected in a parameter:
Report Code Visibility string:
=iif(Parameters!WhichReport.Value(0) = "Occupancy", False, True)
But what I want to do is make the Parameter a multiple select parameter so someone can choose two charts instead of 1 or choose all 6 etc but whatever selection is made all other reports need to stay hidden. Can this be done and if so how?
Thanks
Wayne
You can modify the Hidden expression to achieve this:
Turn all the selected reports into a string using Join, then check if the relevant report name is in the string, something like:
=IIf(
InStr(Join(Parameters!WhichReport.Value, ","), "Occupancy Report") > 0
, False
, True
)
Or, for a different item:
=IIf(
InStr(Join(Parameters!WhichReport.Value, ","), "Capacity Report") > 0
, False
, True
)
Edit after comment:
I guess you're getting mismatches as values like PitchNightsSold and PitchNightsSoldAndCapacity will confuse the expression as written.
I would use a Dataset similar to the following to control item visibility:
Label Value
----- -----
Occupancy Chart1
Pitch Nights Sold Chart2
Capacity Chart3
Pitch Nights Sold And Capacity Chart4
Pitch Nights Sold And Occupancy Chart5
Pitch Nights Sold Capacity And Occupancy Chart6
Then expressions like:
=IIf(
InStr(Join(Parameters!WhichReport.Value, ","), "Chart1") > 0
, False
, True
)
Will only ever apply to one item.
Since these are your own internal constant values, you can call them whatever you want; just make them distinct and unambiguous. The label will remain unchanged so users will be unaffected when running the report.
Edit after comment:
In a comment #glh offers a good solution to similar Value values:
...if you wrap you join in commas and search for them this will remove
the partial finds.
So something like:
=IIf(
InStr("," + Join(Parameters!WhichReport.Value, ",") + ",", ",PitchNightsSold,") > 0
, False
, True
)
Would work very well, too; credit to him for the suggestion.