qsqlquery

Sql query to create a calculated field

為{幸葍}努か 提交于 2019-12-29 07:57:29
问题 I have a database table like this: I hope I can explain this well, so you can understand. I want to calculate how many hours each employee has worked. For example for "Arjeta Domi" we have Cell(2,3) - Cell(3,3) + Cell(4,3) + Cell(5,3), making the difference of each logOut time with Login time. The final table that I want will have these columns: CardNo , UserName , Date , PauseTime , WorkTime I tried this query: taken from the duplicate SELECT DISTINCT [Card NO], [User Name], ( SELECT MIN

Sql query to create a calculated field

↘锁芯ラ 提交于 2019-12-29 07:57:02
问题 I have a database table like this: I hope I can explain this well, so you can understand. I want to calculate how many hours each employee has worked. For example for "Arjeta Domi" we have Cell(2,3) - Cell(3,3) + Cell(4,3) + Cell(5,3), making the difference of each logOut time with Login time. The final table that I want will have these columns: CardNo , UserName , Date , PauseTime , WorkTime I tried this query: taken from the duplicate SELECT DISTINCT [Card NO], [User Name], ( SELECT MIN

Fetch data from two different tables in one query

三世轮回 提交于 2019-12-24 21:04:27
问题 On my webserver there is a database with following two tables: tbl_Friend tbl_Colleague | id | Name | First name | Place | | id | Name | First name | Place | ---------------------------------- ---------------------------------- | 1 | XXXX | XXXXXXXXXX | 1 | | 1 | AAAA | AAAAAAAAAA | 1 | | 2 | YYYY | YYYYYYYYYY | 2 | | 2 | BBBB | BBBBBBBBBB | 3 | | 3 | ZZZZ | ZZZZZZZZZZ | 1 | | 3 | CCCC | CCCCCCCCCC | 4 | Now I want to fetch all Persons from tbl_Friend and tbl_Colleague who live in place 1 .

QSqlQuery how to get value of a count?

对着背影说爱祢 提交于 2019-12-24 03:48:06
问题 I have a query that is just getting the count of table based on some criteria eg: QSqlQuery query("SELECT COUNT(*) FROM some_table WHERE some_value = :something"); query.bindValue(":something", "something"); my question is how do i get result of this back, obviously this is where you would use query.value(int); query.value(QString); But the docs say that int index one shouldnt be used because we dont know what the index would be andi cant use the string one because there is no filed to define

fill the blanks of waterfall from other table

蹲街弑〆低调 提交于 2019-12-24 03:37:56
问题 I have two tables: 1. raw forecast data from forecast table, pulled by snap shot dates, and I use the data to created waterfall looks like this item/snapshot forecast weeks 123 | 8/25/14 | 9/1/14 | 9/8/14 | 9/15/14 -------------------------------------------- 8/24/14| 7661 | 4980 | 588 | 2232 8/31/14| | 8319 | 1968 | 2760 9/7/14 | | | 6931 | 684 9/14/14| | | | 9328 Row labels are snapshot dates, and column labels are forecast weeks. Basically, there are bunch of snapshot dates of the data,

QSqlQuery size() always returns -1

半世苍凉 提交于 2019-12-23 09:36:40
问题 QSqlQuery query; QString queryText("SELECT * FROM section"); query.exec(queryText); qDebug() << query.size(); //always -1 while (query.next()) qDebug() << query.value(0).toString(); //got 16 records Method size() always returns -1. Help, please. Thanks. 回答1: query.size() is not supported with SQLite. But you can get the number of rows with a workaround. QSqlQuery::last () retrieves the last record in the result, if available, and positions the query on the retrieved record. After calling last

Sql where clause not working

不想你离开。 提交于 2019-12-13 08:24:46
问题 SQL where clause is not working in my database. I have a table called "sites" and structure like that id site 1 xyz.com 2 google.com 3 example.com I am running this SQL query SELECT * FROM `sites` WHERE `site` = "google.com"; But I am getting this output MySQL returned an empty result set (i.e. zero rows). (Query took 0.0009 sec) I never see before like that in my life. Update: Screenshot I do not want to apply this query in project. SELECT * FROM `sites` WHERE `site` LIKE "%google.com%"; #

SQL AND OR query

ぐ巨炮叔叔 提交于 2019-12-12 04:54:56
问题 I am trying to select some messages from our customer service queries, WHERE Mmessage owner is ABC, data are LIKE ABCDEF AND message ... AND where the message is either from Customer to CSservice or from CSservice to Customer. How can I do that? SELECT Date, From, To, Data FROM Ccustomers WITH (NoLock) WHERE MSGowner = 'ABC' AND Data LIKE '%ABCDEF%' AND ([From] ='Customer' AND [To] = 'CSservice') OR ([From] ='CSservice' AND [To] = 'Customer') ORDER by Date 回答1: SELECT Date, From, To, Data

QSqlQueryModel with a parent - app crash

佐手、 提交于 2019-12-12 02:26:31
问题 I am rather new to Qt, maybe that's why I cant fully understand the child-parent concept. I need to perform some sql query. I set the QSqlQuery, perform the "prepare and bind" operation and exec it. Next I pass it to the model and display the data. The problem occurs when closing the window - I get a memory violation error. The error occurs only, when I create the model with a parent. Here's the code: QSqlQuery query; query.prepare(QString("SELECT \ %1 as nazwa \ , kontrahentid \ FROM

Insert Strings that contain “ ` ” or “ ' ” to the database table - Qt

纵然是瞬间 提交于 2019-12-11 19:29:20
问题 I have to insert some strings to MySQL database. The problem is that every time I use " ` " or " ' " it causes errors in the QSqlquery execution. How can I prevent this? 回答1: Always use bind variables when running your query and you will never have problems with special characters in SQL queries. Here is an example from the documentation: QSqlQuery query; query.prepare("INSERT INTO person (id, forename, surname) " "VALUES (:id, :forename, :surname)"); query.bindValue(":id", 1001); query