sql-server

One-to-many query and row_number() and conditional aggregation?

99封情书 提交于 2021-02-11 15:05:39
问题 I had a similar issue which was kindly resolved for me by Gordon Linoff Solution by the use of row_number() and conditional aggregation but I don't believe this will work in this instance? I have a hypothetical database for a stamp collection as the image below, were each stamp be can be saved under any of the three conditions in the Status Table and any of the three conditions under the MintUsedTable. Therefore a total of 9 possible States. These are both Lookup Tables and there Id's are

What is the correct DateTimeFormatter pattern for datetimeoffset column

╄→尐↘猪︶ㄣ 提交于 2021-02-11 15:01:35
问题 What is the correct DateTimeFormatter pattern for querying a SQL Server table by a datetimeoffset column. When I execute the below query, I get results. What is the correct pattern I should use to run the same query from the java app? SELECT * FROM TABLE WHERE CreateTimestamp >= '2020-07-06 06:00:00.0000000 +00:00' Below is the java code snippet I use to convert the date: public String convertToDatabaseColumn(OffsetDateTime offsetDateTime) { DateTimeFormatter formatter = DateTimeFormatter

Select the first row of a column in a group of rows within another column

*爱你&永不变心* 提交于 2021-02-11 15:01:18
问题 I have to display a list of the first row of a column within a group of rows within another column Basic Query: SELECT * FROM Table_Example cxp My Table |plan |code |des |month | ----+-------+-------+------+--------+ | 150B | Alpha | etc.a| 1 | ----+-------+-------+------+--------+ | 150B | Beta | etc.b| 2 | ----+-------+-------+------+--------+ | 2600C | Alpha | etc.a| 6 | ----+-------+-------+------+--------+ | 2600C | Alpha | etc.a| 7 | ----+-------+-------+------+--------+ | 2600C | Beta

Tracking continuous days of absence from work days only SQL

爷,独闯天下 提交于 2021-02-11 15:01:11
问题 I'm trying to create a table which takes dates of when a employee is sick and create a new column to provide a "sickness ID", which will identify a unique instance of absence over several dates. I've managed to do this, however I now need to factor in a table which contains the working pattern of each employee, which will let me know if someone was due in work on a given day of the week. This can be joined using the day_no column in both tables along with the employee_number . I posted a this

SQL Help : Exception report - extended

那年仲夏 提交于 2021-02-11 15:00:42
问题 Extend on: SQL help - exception report In my previous post I requested hep for: I have: a company table (CompanyID, CompanyName), Date table (Datekey int, date, isTradingHoliday 0/1), Fact table (id, datekey, companyID, StockClosePrice) I need help to write a query to find for which days and for which companies I don't have data in the fact table. SQL below does the job select c.*, d.* from companies c cross join dates d where d.isTradingHoliday = 0 and not exists (select 1 from facts f where

Invalid object name [dbo].[TriggerName]

隐身守侯 提交于 2021-02-11 15:00:42
问题 I created a trigger named UPDATE_MERCHANDISE . The query completed with one error, a simple typo. I fixed the typo and changed the code to ALTER TRIGGER , but now when I try to execute it I receive the error Invalid object name [dbo].[UPDATE_MERCHANDISE] Why would it be valid when I created it, but not when I try to alter it? Any and all help/ideas would be appreciated. Thanks. USE [CIS31038] GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO ALTER TRIGGER [dbo].[UPDATE_MERCHANDISE] ON [dbo]

Tracking continuous days of absence from work days only SQL

不羁的心 提交于 2021-02-11 14:58:21
问题 I'm trying to create a table which takes dates of when a employee is sick and create a new column to provide a "sickness ID", which will identify a unique instance of absence over several dates. I've managed to do this, however I now need to factor in a table which contains the working pattern of each employee, which will let me know if someone was due in work on a given day of the week. This can be joined using the day_no column in both tables along with the employee_number . I posted a this

SQL Server: SUM by grouped column and sort by another column

允我心安 提交于 2021-02-11 14:56:00
问题 I'd like to combine all like Locations (name) and SUM the Volume (vol) for that location and order the results by Day of Month here. I attempted to Select a subset and inner join the values like here but kept getting group by not in aggregate clause errors, thank for the hints!! Results should be ordered by day of month and lines with the same location on same day should be summed on one line instead of multiple lines. Here is my Select Statement without grouping or summing: SELECT day_of

determining the staff's title when a certain transaction is done

こ雲淡風輕ζ 提交于 2021-02-11 14:54:38
问题 I have a transaction table with relevant data and username. and also, there is a another table that stores staff's title history by date. However, title history table doesnt have log of every single day. Here is an example of my transaction table: username tran_date amount -------- ---------- ------ anderson 16/02/2019 1200 julie 17/02/2019 54000 williams 20/02/2019 32650 and staff's title log table: username date title -------- ---- ------ anderson 01/01/2019 assistant anderson 06/04/2019

.NET Core Web API Application cannot connect to SQL server running on Docker

别来无恙 提交于 2021-02-11 14:49:16
问题 Using MAC. Error (provider: TCP Provider, error: 40 - Could not open a connection to SQL Server). Connection string "Data Source=localhost,1433;Initial Catalog=MyDatabase;Integrated Security=True;User id=sa;Password=MyPassword;MultipleActiveResultSets=true" Using .NET Core 3.1. The Web API is running in a container The database is running on docker container. ports mapped 1433:1433 Able to query the database from Azure Data Studio. But while trying to connect from .net.core application it