firebird2.1

how to combine tables with 1 to many relationship into 1 line of record

泄露秘密 提交于 2019-12-08 03:43:32
问题 I need to combine two tables with 1 to many relationship using union but to no success. I've been trying to use this code select a.equipmentid, a.codename, a.name, a.labelid, a.ACQUISITIONDATE, a.description from TBL_EQUIPMENTMST a where a.partofid = '57' union all select first 1 b.warrantyid, b.startdate, b.enddate from tbl_equipwarranty b inner join TBL_EQUIPMENTMST c on b.equipmentid=c.equipmentid where c.partofid = '57' and b.servicetype='service' order by b.warrantyid desc union all

how to combine tables with 1 to many relationship into 1 line of record

一个人想着一个人 提交于 2019-12-06 13:37:06
I need to combine two tables with 1 to many relationship using union but to no success. I've been trying to use this code select a.equipmentid, a.codename, a.name, a.labelid, a.ACQUISITIONDATE, a.description from TBL_EQUIPMENTMST a where a.partofid = '57' union all select first 1 b.warrantyid, b.startdate, b.enddate from tbl_equipwarranty b inner join TBL_EQUIPMENTMST c on b.equipmentid=c.equipmentid where c.partofid = '57' and b.servicetype='service' order by b.warrantyid desc union all select first 1 d.warrantyid, d.startdate, d.enddate from tbl_equipwarranty d inner join TBL_EQUIPMENTMST e

How can you detect a parent with a nested relationship in a database using SQL?

寵の児 提交于 2019-12-05 08:17:11
I'm using Firebird 2.1. There is a table name Folders , with the fields: FolderID ParentFolderID FolderName ParentFolderID is -1 if it's the root folder -- otherwise it contains the parent folder's ID. How can I find all parents (up to the root folder) of a low level node? Do I need a recursive query? ( Firebird supports them ) Something like this: WITH RECURSIVE hierarchy (folderid, ParentFolderId, FolderName) as ( SELECT folderid, ParentFolderId, FolderName FROM folders WHERE ParentFolderID = -1 UNION ALL SELECT folderid, ParentFolderId, FolderName FROM folders f JOIN hierarchy p ON p

Firebird 2.1 - Simple SELECT

做~自己de王妃 提交于 2019-12-01 23:29:27
I would like to union some data, but a simple select example not working. Selecting existing tables work fine... SELECT 1 as foo Message: can't format message 13:896 -- message file C:\xxxx\firebird.msg not found. Dynamic SQL Error. SQL error code = -104. corrupt pool. In MySQL and Postgres is no problem with these simple select.. Thanks for help! Firebird (like many other DBMS) requires a FROM clause. In Oracle you'd use the DUAL table, in Firebird you can use RDB$DATABASE SELECT 1 as foo FROM RDB$DATABASE; As RDB$DATABASE always contains exactly one row, this works the same way as Oracle's

How to get all the fields of a row using the SQL MAX function?

大憨熊 提交于 2019-11-29 00:14:55
Consider this table (from http://www.tizag.com/mysqlTutorial/mysqlmax.php ): Id name type price 123451 Park's Great Hits Music 19.99 123452 Silly Puddy Toy 3.99 123453 Playstation Toy 89.95 123454 Men's T-Shirt Clothing 32.50 123455 Blouse Clothing 34.97 123456 Electronica 2002 Music 3.99 123457 Country Tunes Music 21.55 123458 Watermelon Food 8.73 This SQL query returns the most expensive item from each type: SELECT type, MAX(price) FROM products GROUP BY type Clothing $34.97 Food $8.73 Music $21.55 Toy $89.95 I also want to get the fields id and name that belong to the above max price, for

In FirebirdSql, how to return exception message from procedure

丶灬走出姿态 提交于 2019-11-27 15:39:44
I want to return the error message from a procedure when an exception happens. In SQL Server you would select the Error_Number() and Error_Message(). How would I do it in FirebirdSql SET TERM ^ ; CREATE PROCEDURE sprocname ( id int ) RETURNS ( gcode int, errmsg varchar(250) ) AS BEGIN gcode = 0; errmsg = ''; -- do procedure code here WHEN ANY DO BEGIN gcode = gdscode; -- ?? errmsg = ??; END SUSPEND; END^ SET TERM ; ^ Unfortunately you will need to do that at the client side, as it is currently not possible to obtain this in PSQL. There is a feature request in the Firebird tracker, which has

How to get all the fields of a row using the SQL MAX function?

一曲冷凌霜 提交于 2019-11-27 15:17:10
问题 Consider this table (from http://www.tizag.com/mysqlTutorial/mysqlmax.php): Id name type price 123451 Park's Great Hits Music 19.99 123452 Silly Puddy Toy 3.99 123453 Playstation Toy 89.95 123454 Men's T-Shirt Clothing 32.50 123455 Blouse Clothing 34.97 123456 Electronica 2002 Music 3.99 123457 Country Tunes Music 21.55 123458 Watermelon Food 8.73 This SQL query returns the most expensive item from each type: SELECT type, MAX(price) FROM products GROUP BY type Clothing $34.97 Food $8.73 Music

Filter sql based on C# List instead of a filter table

空扰寡人 提交于 2019-11-27 09:39:04
Say I have a table with the following data: Now I want to filter by the primary keys department and number. I have a list of department and number combinations that have to be filtered in code. In my mind, I would create a join that results in the following: select * from employee e inner join dynamicTable dyn on e.Department = dyn.Department and e.Number = dyn.Number; dynamicTable is my List in C# code that has the primary keys to filter, but I don't know how to pass this list to the database level. I dont't want to load everything from my employees table and that filter in code by linq or