Quantcast
Channel: dBforums – Everything on Databases, Design, Developers and Administrators
Viewing all 13329 articles
Browse latest View live

Some SQl files as a database

$
0
0
Hi

I have a database but also have a number of files on sql that need to be linked to the data base.

this is an estimating software so I will need to open another program compile the estimate then import the information into the
the database via sql into a form .

can we use crystal reports to produce report from BDB?

Works as Query, but not as Function

$
0
0
So, I've got this query that doesn't work as a function. Can someone tell me why?
Query:
Code:

    SET @ADDR_NUM = 5308;
    SET @ADDR_DIR = 'W';
    SET @ADDR_STR = '96th';
    SET @ADDR_TYPE = 'St';
    SET @ADDR_PDIR = '';

    SELECT `WD`
    FROM data.street_index
    WHERE `STREET` LIKE @ADDR_STR COLLATE utf8_unicode_ci
    AND @ADDR_NUM >= `LO_RANGE`
    AND @ADDR_NUM <= `HI_RANGE`
    AND `DIR` LIKE @ADDR_DIR COLLATE utf8_unicode_ci
    AND `TYPE` LIKE @ADDR_TYPE COLLATE utf8_unicode_ci
    AND `PDIR` LIKE @ADDR_PDIR COLLATE utf8_unicode_ci
    AND IF(@ADDR_NUM % 2 = 0, `EOB` LIKE 'E' COLLATE utf8_unicode_ci OR `EOB` LIKE 'B' COLLATE utf8_unicode_ci, `EOB` LIKE 'O' COLLATE utf8_unicode_ci OR `EOB` LIKE 'B' COLLATE utf8_unicode_ci);

Function:
Code:

CREATE DEFINER=`root`@`localhost` FUNCTION `GetDistrict`(ADDR_NUM INT(5), ADDR_DIR VARCHAR(1), ADDR_STR VARCHAR(128), ADDR_TYPE VARCHAR(3), ADDR_PDIR VARCHAR(1)) RETURNS int(1)
BEGIN
    DECLARE wd INT(1);
   
    SELECT `WD` INTO wd
    FROM data.street_index
    WHERE `STREET` LIKE ADDR_STR COLLATE utf8_unicode_ci
    AND `LO_RANGE` <= ADDR_NUM
    AND `HI_RANGE` >= ADDR_NUM
    AND `DIR` LIKE ADDR_DIR COLLATE utf8_unicode_ci
    AND `TYPE` LIKE ADDR_TYPE COLLATE utf8_unicode_ci
    AND `PDIR` LIKE ADDR_PDIR COLLATE utf8_unicode_ci
    AND IF(ADDR_NUM % 2 = 0, `EOB` LIKE 'E' COLLATE utf8_unicode_ci OR `EOB` LIKE 'B' COLLATE utf8_unicode_ci, `EOB` LIKE 'O' COLLATE utf8_unicode_ci OR `EOB` LIKE 'B' COLLATE utf8_unicode_ci);

RETURN wd;
END

Example Data:
Code:

PRECINCT | DIR | STREET  | TYPE | PDIR | CITY    | LO_RANGE | HI_RANGE | E/O/B | ZIP  | CG | LG | JD | CB | BR | WD
----------------------------------------------------------------------------------------------------------------------
46      | W  | 96TH    | ST  |      | OAK CITY | 5300    | 5318    | B    | 12345 | 3  | 36 | 4  | 11 | 1  | 3
46      | W  | 96TH    | ST  |      | OAK CITY | 5334    | 5568    | B    | 12345 | 3  | 36 | 4  | 11 | 1  | 3
21      | W  | 96TH    | ST  |      | OAK CITY | 6800    | 7148    | E    | 12345 | 3  | 31 | 4  | 6  | 1  | 1

Function Query:
Code:

select data.GetDistrict(5308, 'W', '96th', 'St', '') AS `DISTRICT`;
When I run the query, it returns '3'. That is correct.
When I run the function, it returns null.

Wanted : MySQL Scripts

$
0
0
Hi Guys,

I'm looking for scripts in MySQL to be used as lab materials. 2 types of scripts i'm looking for:

1) Raw scripts to demonstrate use of any of the following:
- hierarchical data
- self join
- case when
- complex join
- complex update/insert/delete
- any scripts that uses clever approach

2) Raw ETL scripts in MySQL (not talend, kettle etc) ETL can be for data migration and/or data integration. example scripts:
- scripts handle hierarchical data.
- transform address_line1, address_line2 -->>> street_num, street_name, unit_num
- simple data integration : extract, cleanse, conform, ... etc transform, load
- contains simple staging area design


I don't need full schema, just related tables, sample data and scripts.

Thanks in advance!

alfred

Views not displayed in view folder

$
0
0
Hi
I have created a view in Pervasive but the view does not show in the view folder.
I also tried to recreate it and I get the message view already exists.
Can some one help.
here is how the view was created.
Code:

CREATE VIEW vista as
select "FIELD_NAME","MASK" FROM "ORDE_WB_MASK"
 WHERE "FIELD_NAME" = 'FileCreate'

Views not displayed in view folder in PCC

$
0
0
Hi
I have created a view in Pervasive but the view does not show in the view folder.
I also tried to recreate it and I get the message view already exists.
Can some one help.
here is how the view was created.
Code:

CREATE VIEW vista as
select "FIELD_NAME","MASK" FROM "ORDE_WB_MASK"
 WHERE "FIELD_NAME" = 'FileCreate'

Equal Allocation of data

$
0
0
Dear All,
I've an Access table which contains different Queue names wise data, I want to simply divide the number of records in equal parts by selecting each Queue name, for example I've a Queue called "CH_SUPPORT_JEOPARDY" which contains 20 records I want a update data with Q1, Q2, Q3, Q4 and Q5, by set of 4 each and for odd number of records it should be distribute as even as possible

With Regards
Manik Nag
Database2.zip
Attached Files

Hyperlinking Digitally Signed Word Docs into Access

$
0
0
Hello Everyone!

I am new here and new to Access. I do have some experience with Excel and a little experience with VBA. My situation is that I work for a non-profit center and am developing a new client database system from scratch and am learning as I go.

I want to link client word docs into a "Documents" tab for each client record (no prob). However, since each document needs to be reviewed and digitally signed by a supervisor, is there a way to flag/highlight/whatever files that have not yet been signed?

Or is there some way to create a "Submit for Review" button, that would allow the document to show up in some location for supervisor review?

If anyone has a better idea, I am all "ears."

Thanks,

TD

“P1: begin” and “P2: begin” in a DB2 Stored Procedure

$
0
0
Can anyone explain to me or point me to some documentation on why the stored procedures are tagged into different parts using "P1: begin" and "P2: begin" ? Thanks, Mike

AGGREGATE FUNCTION TO BE USED ONLY IN SEARCH CRITERIA (where clause)

$
0
0
INPUT

Clabcd no C_Chck C_Typ A_AMT B_AMT
222222222222200 1 1 50 40
222222222222201 4 1 -20 -10
3333333333333300 2 2 12 22
3333333333333302 3 2 -10 -15

OUTPUT

SUBSTR(Clabcdno, 1, 13) C_Chck C_Typ AMOUNT_PAID
2222222222222 1 1 50
2222222222222 4 1 -20
33333333333333 2 2 22
33333333333333 3 2 -15


Input comes as 15 digits for clabcd no but we take only the first 13 digits SUBSTR(Clabcdno, 1, 13)
For C_Typ =1, A_AMT= 50 – 20 = 30 which is > 0 so it it displayed in the output ( for SUBSTR(Clabcdno, 1, 13) = 2222222222222)
For C_Typ = 2, B_AMT = 22-15 = 7 which is > 0 so it is displayed in the output ( for SUBSTR(Clabcdno, 1, 13) = 33333333333333)

How do i check this condition in the search criteria (Where clause)? Input is 4 records, i need to sum the amount fields which would make it one record, but still i need all the 4 records in the output.
subquery might help if only one SUM field is there i guess. Here 2 SUM fields A_AMT and B_AMT are used and also subquery would cause performance issue.

I already have 2 left outer joins and one union. This is an additional change needed for the query.


Any help is appreciated. Thanks

AGGREGATE FUNCTION TO BE USED ONLY IN SEARCH CRITERIA (where clause)

$
0
0
INPUT

Clabcd no C_DISP C_TYPE A_AMT B_AMT
222222222222200 1 1 50 40
222222222222201 4 1 -20 -10
3333333333333300 2 2 12 22
3333333333333302 3 2 -10 -15

Input comes as 15 digits for claim no but we take only the first 13 digits SUBSTR(Clabcd no , 1, 13)
For C_TYPE =1, A_AMT = 50 – 20 = 30 which is > 0 so it it displayed in the output ( for SUBSTR(Clabcd no , 1, 13) = 2222222222222)
For C_TYPE = 2 (C_TYPE other than 1), B_AMT= 22-15 = 7 which is > 0 so it is displayed in the output ( for SUBSTR(Clabcd no , 1, 13)= 33333333333333)

OUTPUT

SUBSTR(Clabcd no , 1, 13) C_DISP C_TYPE AMOUNT_PAID
2222222222222 1 1 50
2222222222222 4 1 -20
33333333333333 2 2 22
33333333333333 3 2 -15


Input has 4 records, SUM should be done on the 2 fields and output should display all the 4 records.
How do i use aggreagte function in the search criteria?
Subquery can be used i guess but since 2 amount fields are used its not possible. and also subquery causes performance issue.

My query already has 2 left outer joins and also one union. This is an additional change

Any help is appreciated. Thanks

Tuning SQL queries

DB2 Trigger error

$
0
0
Hi,

I am getting the below error on my db2 trigger. Can you please help me understand what this error is and how to fix it?

Trigger:

CREATE TRIGGER SCS.B_TRIG_INSERT_STORE_CONFIG AFTER INSERT OR UPDATE ON SCS.B_L2B_CONFIG REFERENCING NEW AS i NEW_TABLE AS n FOR EACH ROW MODE DB2SQL
BEGIN ATOMIC
DECLARE v_build_num VARCHAR(10);
DECLARE v_consolidated_count INTEGER DEFAULT 0;

SET v_build_num = substr(i.BUILD_NUM,1,locate('-',i.BUILD_NUM)-1);

SELECT 1 into v_consolidated_count
FROM SCS.B_STORE_CONFIG
WHERE STORE_NUM = i.STORE_NUM AND
CONFIG_NAME = 'ConsolidatedSecurity';

IF ( v_consolidated_count = 0 ) THEN
IF CAST(v_build_num AS INT) > 4589 THEN
INSERT INTO SCS.B_STORE_CONFIG VALUES
(i.STORE_NUM, 'ConsolidatedSecurity', 'Yes');
END IF;
END IF;

END^
CONNECT RESET^

Error:

DB21034E The command was processed as an SQL statement because it was not a
valid Command Line Processor command. During SQL processing it returned:
SQL0104N An unexpected token "v_consolidated_count" was found following
")-1); SELECT 1 into". Expected tokens may include: "<space>". LINE
NUMBER=8. SQLSTATE=42601

Thanks
Anis GovindaRao

1-N Relationship can be table-needed

$
0
0
Hi buddies!
It's our master question, Is there any situation which a 1-n relationship needs table? if yes, bring an example.
I know in a normal situation it doesn't need table, put "1" side foreign key in "n" side table is all we need.

PowerPivot and DBF files linking?

$
0
0
I recently had PowerPivot installed but have not used it much. Additionally, I'm losing Access 2003 and my ability to query DBF files exported from our system. Is there any way to link these databases into PowerPivot to query them? I tried opening the files in Excel to save them as a different format that I could then query in newer versions of Access (DBF not supported in later versions) but Excel had some trouble reading some fields so I thought I'd see what PowerPivot can do.

Joshua

Removing db2tschg.his file

$
0
0
Running DB2 V9.7 Enterprise Edition on Windows. db2tschg.his file is 6 GB in size and I would like to remove it.

I have read that it can be deleted and a new file will be generated (much like renaming the DB2Diag.log)

here is the article: http://www-01.ibm.com/support/docvie...id=swg1IY86984

Can this file just be renamed and moved on the fly with the instance running???

Invoicing System

$
0
0
Hi James,

1.As talk in PM, i'm searching a way to get a ''user input'' for the quantity of a product at the moment of adding the product in an m2m invoice form.

2. If i select the product added in the m2m and i correct the quantity manually: I'm getting well the result of quantity x unit price = total cost line in m2m but can't get the result of the total cost of all line of this m2m in another single field of the invoice form.

Thanks alot,
Martin

How to add a user to SYSDEBUG role

$
0
0
Hi,

I am trying to debug a procedure on linux with db2 10.5 using IBM data studio. I am getting a popup as Userid is not a member of SYSDEBUG role.I have given all the required privileges like DBADM,SECADM etc.

Can some one kindly let me know how to add a user to the SYSDEBUG role.

Thanks

inserting records

$
0
0
I would like to insert lines (records) in list/tabel-view, in Access or Filemaker 10 (this is what I currently use),
so that I can keep matching records together when I add them.
Adding new records at the bottom and sorting the list is not practical for me.
Is this possible?
If not in Access/Filemaker, is there maybe other software that allows this?

Chris

Financial Table

$
0
0
table.png

i have transaction table like left table. my question is how can i make additional column without add it to original table, like an alias column, so my table will be looked like the right table, balance column only make math operation. if the id is "db" then subtract the balance, if id is "cr" then add the balance.
how is the query i need to make that right table from left table?

thanks for the help! :D
Attached Images

My Database setup with huge amounts of time-series data. Experience? Suggestions?

$
0
0
** note To start out, let me just say that when it comes to computers I'm completely self taught. I stated learning web development and database about 2 months ago. most of my experiance is with linux admin and general programming

My project
I am an electrician by trade and am in charge of(doing it myself) building on an online metering system that consists of a device you install next to your main power panel, and a web portal where you can view your data. Inside the device is a small linux based computer that handles all the data logging local storage(sqlite or mysql) and real-time analytic's. Once the computer has finished its calculations it uploads the meter data to a cloud based database (mysql on digital ocean) where the data can be viewed from a webapp(that i'm also building).

My Data/schema
The device is currently uploading 122 columns of floats* with an incrementing id(which is probably not needed) and a datetime. This is uploaded every 2 seconds for a total of 43,200 rows per day. (yes I need it that frequently, I need some of it at .125 second intervals or as fast as i can get it.)
The device is also uploading calculated aggregations(sums, min, max, average, and some trig and integrals) for time periods of 60s (1 min) 300s and (5 min) 900s all of which are calculated off of the 2 second data plus additional data stored in buffers on the device.
additional tables with event data, 1 row/record per event, and daily statistics(single row per day)

*(values range from 0 to 1000000 rounded to 5th decimal place .00001)

example database layout per meter:

meter_data...................<- database name
----meter1_2ss..............<- 2 second data table with 124 columns
----meter1_60ss............<- 60 second data table with 210 columns
----meter1_300ss..........<- 300 second data table with 210 columns
----meter1_900ss..........<- 900 second data table with 210 columns
----meter1_events.........<- events table with haven't designed yet
----meter1_daily............<- daily statistics table haven't implemented yet
----meter2_2ss..............<- 2 second data for another device
----meter2_60ss............<- 60... every meter has the same tables

I'm using Innodb with barracuda and file_per_table=on
with this setup 1 months worth of data comes in at just over 1.3 million rows and a file size (with barracuda compression enabled) of about 200 mb.
Just looking at the above I noticed that as a minimum I could merge the 60, 300, and 900 second tables together and add an indexed time period identifier.
For reference I leaned everything I know about databases on this project. I learn best by just jumping right in and then having to fix whatever i screw up(note this only applies to my own projects...) I don't expect anyone here to teach me the nitty gritty details of schema/database planning or design. Thats on my personal to-learn list (although if you have suggested learning material or links i'm grateful :) ) When i designed this I knew just about nothing about database's in general, and now I know enough to know that this is probably a bad setup and that when I can afford it I should hire someone to help me design a better system. But until then(could be awhile) I'm stuck doing this by myself And I need to come up with a design/method... that will scale. One of the goals I have is to store the data for as long as possible, and as a minimum 2 years. As of right now I have 2 devices set up and working, I'm in the process of adding 10 more right now. Our company specializes in designing power quality improving equipment and we are going to be installing one of these devices with every system we sell; so I'll probably have 100 more by the end of the year.



Tools i'm using
MySQL 5.5
Python SQL alchemy (just for table creation for now, ORM's are just as hard to learn as SQL, especially when you don't even know much SQL)
official python MySQL connector with compressed protocol and prepared statements

My Concerns(Ya, I know you probably have more.)

  1. For now with 2-10 devices this works, well what about when I have more, 100's 1000's
  2. As it is setup now with 100 devices the database will be between 150GB and 240GB within a year. Were also going to start selling this device standalone, so that number could shoot up fast. Right now Its setup on a cloud database that purges the 2 seconds after 8 days, and replicated to local database i set up at my office for long term storage, That will only work till the replication maxes out our internet connection. Whats the best cost effective way to try and host this?
  3. Is MySQL the right database for this? Would something like Postgres or Mongo be better?
  4. At 100 devices that will have the database processing 4.43 million inserts a day. Can a database handle that many inserts? If not is there a technology that would?
    Ive come across schema designs where all the time-series data was placed in a single table with device identifiers. Would than work for my 2 second data? is it advisable? (http://stackoverflow.com/questions/4...ational-or-non)


I neither need nor expect anyone to post a 5000 word explanation on how best to do anything, If you want to take the time to do that, that's fine and thank you. I'm looking for basic advice, and community experience, as it's pretty obvious I don't have any. I'll be grate-full for whatever I get, even if I have to google for a week to understand it.

Thanks
Jake
Viewing all 13329 articles
Browse latest View live