|
Hi,
as you act on a column within the select "......" statements,
you must add "group by" and the column involved.
It's from Sql engine,
in a step : it gather the columns,
in a late step : a rollback is made to apply the 0.95* operation on all selected columns.
so the "group by" recall all the 'columns' for sorting the "whole gathered" one by one.
It's really inner mechanicals SqlEngine work.
Remenber : when operation on columns in the 'select' : as "label" / maths .. , string works
add "group by" with the column required.
modified 23-Aug-21 21:01pm.
|
|
|
|
|
I'm really not following this at all. Perhaps if you make the amendments you are speaking about and post that code here I might understand it better?
Or if you have a link to the specific documentation that might help?
|
|
|
|
|
one other error I see :
from -->"tables required"<-- where column-n =<.. ( sub request ).
add as fix the table needed for the first query ( the first part )
I think you have to go on taxes early ,
insert into tax_tab (n_amount, paid) values amount=n_amount , 0.95*n_amount ;;
modified 23-Aug-21 21:01pm.
|
|
|
|
|
Sorry, I still do not understand what you are saying. Please post the code here to illustrate your point.
There are no errors reported in my code - or do you think you are replying to the Original Poster?
|
|
|
|
|
Hello:
My MySQL database version is 5.6.35 and I use InnoDB.
I want to remove the Delete and Drop Table permissions of the user U1 from the table T1 in the db1 database.
The operating instructions are as follows:
<pre lang="SQL">
Revoke delete,drop on db1.T1 from U1;
No error message appeared after execution.
But after execution, the user U1 can still use the DELETE command to delete the data row in the data table T1.
You can also use the DROP TABLE command to delete the data table T1.
Thanks for replying.
|
|
|
|
|
|
Hi,
I am looking a sandwich query for my attendance module, If the employee is absent on Saturday and Monday then sunday will be calculate as Absent the same has to be case of holidays.
The attendance table structure in SQL 2005 as per below.
EmpCode
EmpShift
AttDate
AttStatus
.
.
Please Advice/provide some solution for the above.
Thanks & Kind Regards
Mohammad Salmani
|
|
|
|
|
Mohammad Salmani wrote: provide some solution Sorry, this site does not provide code to order. Google will find you many SQL tutorials that will help.
|
|
|
|
|
LEFT JOIN to a table that has all dates and find those that do not have a match.
|
|
|
|
|
I am having the below data in Attendance Table
EmpCode AttMonth AttYear AttDate ShiftCode AttStatus
1 6 2021 2021-06-01 00:00:00.000 1001 P
1 6 2021 2021-06-02 00:00:00.000 1001 P
1 6 2021 2021-06-03 00:00:00.000 1001 P
1 6 2021 2021-06-04 00:00:00.000 1001 P
1 6 2021 2021-06-05 00:00:00.000 1002 A
1 6 2021 2021-06-06 00:00:00.000 1009 WO
1 6 2021 2021-06-07 00:00:00.000 1001 A
1 6 2021 2021-06-08 00:00:00.000 1001 P
1 6 2021 2021-06-09 00:00:00.000 1001 P
I need to update 'WO' as 'A' while processing attendance
please help for the above.
|
|
|
|
|
I can't help because I do not understand what you need help with.
|
|
|
|
|
A few SQL functions may be of help for you ..
Take a look at this query
SELECT *,DATEPART(wk, AttDate) As 'Week Number',DATEPART(weekday, AttDate) As 'Week Day', DATENAME(WEEKDAY,ATTDATE) FROM #TEMP1
|
|
|
|
|
I would do the as 3 queries:
1 get the first absent date date - store it in date1 variable
2 get the next absent date > date 1 - if it exists store it in date2 variable
If date2 is not null (more than 1 day)
3 set all records between date1 and date2 to absent
This covers multi day holidays.
Never underestimate the power of human stupidity -
RAH
I'm old. I know stuff - JSOP
|
|
|
|
|
But this will only work on 1 record at a time.
|
|
|
|
|
One Employee at a time, correct. So put it in a loop through all employees.
Never underestimate the power of human stupidity -
RAH
I'm old. I know stuff - JSOP
|
|
|
|
|
Hi,
I have implemented as per below query,If Employee is absent on Saturday and Monday the weeklyoff should be counted as Absent. I have passed the process date parameter in place of static date.
SELECT A.EmpCode,A.AttDate As Sundate FROM Attendance_Details A INNER JOIN (SELECT A.Empcode,A.AttDate As SatDate,A.AttStatus As SatStatus
FROM Attendance_Details A INNER JOIN (SELECT EmpCode,AttDate As MonDate,AttStatus As MonStatus FROM Attendance_Details
WHERE AttDate='2021-06-07' AND DATENAME(WEEKDAY, '2021-06-07') = 'Monday' and AttStatus IN ('A','HL'))T ON T.EmpCode=A.EmpCode
WHERE DATENAME(WEEKDAY, DATEADD(day,-2,'2021-06-07')) = 'Saturday' AND AttStatus IN ('A') AND AttDate=DATEADD(day,-2,'2021-06-07'))T1
ON A.EmpCode=T1.EmpCode AND DATENAME(WEEKDAY, DATEADD(day,-1,'2021-06-07')) = 'Sunday' AND AttStatus NOT IN('AL','SL','PL','ML','FL') AND AttDate=DATEADD(day,-1,'2021-06-07')
Please help to improve the above query...
Thanks & Regards
Mohammad Salmani
|
|
|
|
|
Mycroft Holmes wrote: loop Loops are a last resort in databases. They are built to work on sets.
|
|
|
|
|
Hello,
I am trying to load a json file from network location into a table on sql server 2016. The domain account has access to both the file on network as well as the database.
I keep receiving this message:
Cannot bulk load because the file "\\<networklocation>\loaddata.json" could not be opened. Operating system error code 5(Access is denied.).
In the above error message, does the user not have access to file or to perform the "bulk load" action?
Much appreciated!
|
|
|
|
|
Also, I am using Windows authentication for SQL server, and this same user also has access to the share on network.
|
|
|
|
|
I think it means that the SQL Server identity (not the user) does not have access to the network drive. I always move the file to the SQL Server server or loaded it via c#.
Loading via c# I would put into a datatable EXACTLY matching the destination table and use BULKCOPY [^] to insert it into the destination
Never underestimate the power of human stupidity -
RAH
I'm old. I know stuff - JSOP
|
|
|
|
|
I'll swear I have this right
The field is smalldatetime . I'm just picking up the record and inserting it.
On select, I used
CONVERT(varchar(33), ADD_DATE, 121) AS ADD_DATE,
Oninsert, the sql looks like this
'1900-01-01 00:00:00.000'
I read up on sql date times and the different formats. If I pick it raw, and try o insert it, I get an object error.
In SQL Manager, I get
Conversion failed when converting character string to smalldatetime data type.
Warning: sqlsrv_fetch_array() expects parameter 1 to be resource, bool given in C:\App\Dev\PCAD\repository\projectOrder.repository.php on line 1182
Array ( [0] => Array ( [0] => 22007 [SQLSTATE] => 22007 [1] => 295 [code] => 295 [2] => [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Conversion failed when converting character string to smalldatetime data type. [message] => [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Conversion failed when converting character string to smalldatetime data type. ) ) addProjectCost 1749 INSERT INTO [proj_cost] ( Proj_ID, Proj_Stage, Vers_ID, Task_ID, Task_Oper, Task_Class, Vend_ID, CO_Proj_Type, CO_Type, CO_Type_D, CO_Value, Cost, ADD_NO, ADD_DATE, ADD_CODE, Pref_Vendor, User_Last_Upd, Delete_Flag ) VALUES ( '2549', 'engineering', '0', 'TK_AT_001', '85', 'OP', '', '39', 'PoolSpa', 'REF_AT_002', '', '25', '175', '0', '1900-01-01 00:00:00.000', '', 'jimk', 0 ) - 1
If it ain't broke don't fix it
Discover my world at jkirkerx.com
|
|
|
|
|
That is why you used parameterized queries instead of strings.
Never underestimate the power of human stupidity -
RAH
I'm old. I know stuff - JSOP
|
|
|
|
|
jkirkerx wrote: INSERT INTO [proj_cost] ( Proj_ID, Proj_Stage, Vers_ID, Task_ID, Task_Oper, Task_Class, Vend_ID, CO_Proj_Type, CO_Type, CO_Type_D, CO_Value, Cost, ADD_NO, ADD_DATE, ADD_CODE, Pref_Vendor, User_Last_Upd, Delete_Flag ) VALUES ( '2549', 'engineering', '0', 'TK_AT_001', '85', 'OP', '', '39', 'PoolSpa', 'REF_AT_002', '', '25', '175', '0', '1900-01-01 00:00:00.000', '', 'jimk', 0 )
I guess the VALUES list does not correspond the fields list, so the value form ADD_DATE seems to be '0' rather than '1900-01-01 00:00:00.000'.
|
|
|
|
|
I thought about what you both said, and would like to say thanks and show gratitude as well.
I went back and keep the Select statement raw, took the convert out.
The dumped my CRUD function to add the record, and converted the calling function to SQL.
Then used PHP to convert the raw date object I picked up to a string, and declared it in SQL.
I suppose I could go back to my add CRUD function and do the conversion there instead
$result2 = sqlsrv_query($conn, $query2) or die(" setDbProjectCost " . LINE . " - " . $query2 . " - " . print_r(sqlsrv_errors()));
if (sqlsrv_has_rows($result2)) {
$row2 = sqlsrv_fetch_array($result2);
$addDateString = $row2[13]->format('Y-m-d H:i:s') . '.000';
$query3 = "
DECLARE @addDate AS VARCHAR(33) = '$addDateString';
INSERT INTO [proj_cost]
VALUES ... @addDate
If it ain't broke don't fix it
Discover my world at jkirkerx.com
|
|
|
|
|
If I run a SQL statement, like this:
SELECT * FROM my_table
is there any SQL statement / trick to find the name of every column from '*' ?
Because if I write:
SELECT id, name, age FROM my_table
yes, I could extract the columns name, by text analyze. But how about '*' case ?
|
|
|
|
|