stored-procedures

Case in an INSERT INTO Statement

半腔热情 提交于 2021-01-28 18:54:58
问题 I am trying to set the ActionReq column of this stored procedure to the value of Expiration + the AdvancedCancel when an ActionReq is not supplied. ActionReq and Expiration are datetimes and AdvancedCancel is an int. How do I do thi? My SQL skills are very basic. ALTER PROCEDURE [dbo].[insertIntoGrid] @Vendor nvarchar(max), @Product nvarchar(max), @Type nvarchar(max), @AccountCode nvarchar(max), @2016AccCode nvarchar(max), @BusinessUnit nvarchar(max), @Group nvarchar(max), @TIAYTD nvarchar

Finding Gaps in Timestamps for Multiple Users in PostgreSQL

好久不见. 提交于 2021-01-28 11:48:59
问题 I am working with a dataset containing Check-In and Check-Out times for multiple office rooms over the last 5 years. One of the projects I was asked to work on was calculating the amount of time each room is busy and vacant over various time ranges (daily, weekly, monthly, etc.) assuming normal operational hours (8am to 5pm). A sample of the dataset for two days looks like this: room_id start_dt end_dt Room: Room 3 2019-05-04 09:00:00 2019-05-04 11:30:00 Room: Room 3 2019-05-04 11:30:00 2019

Finding Gaps in Timestamps for Multiple Users in PostgreSQL

帅比萌擦擦* 提交于 2021-01-28 11:39:27
问题 I am working with a dataset containing Check-In and Check-Out times for multiple office rooms over the last 5 years. One of the projects I was asked to work on was calculating the amount of time each room is busy and vacant over various time ranges (daily, weekly, monthly, etc.) assuming normal operational hours (8am to 5pm). A sample of the dataset for two days looks like this: room_id start_dt end_dt Room: Room 3 2019-05-04 09:00:00 2019-05-04 11:30:00 Room: Room 3 2019-05-04 11:30:00 2019

JSON Nested Object to SQL Server Stored Procedure

五迷三道 提交于 2021-01-28 09:00:51
问题 I am trying to insert multiple rows from a single JSON object, where each row is the n'th name/value pair in the JSON nested-object Here is what the SQL Server table looks like: ID | Name | Value | Here is what the JSON looks like: { "PropData":{ "Name1": "Value1", "Name2": "Value2", "Name3": "Value3" } } Here is what I have so far for the stored procedure ( ID is static and should be the same for each row - I've left out how that is retrieved for brevity as it isn't relevant to the question)

Call SQL Stored Procedure from PHP PDO

孤者浪人 提交于 2021-01-28 05:18:37
问题 I need to call a stored procedure to insert the data to sql and it return a value with output parameter like CREATE PROCEDURE InsertInfo @userid VARCHAR(100), @login_time DATETIME, @IsSuccuess BIT, @loginid INT OUTPUT AS BEGIN INSERT INTO Audit_LoginLogoutAttempt(UserID,Login_Time, IsSuccuess, DateCreated) VALUES (@userid,@login_time,@IsSuccuess, GETDATE()) SET @loginid = @@IDENTITY END GO How to send input and output parameters using PHP $stmt = $conn->prepare("{CALL InsertInfo(?, ?, ?, ?)}"

SQL Server 2008 stored procedure result as column default value

早过忘川 提交于 2021-01-28 04:38:03
问题 First of all, thank you guys. You always know how to direct me when I can't even find the words to explain what the heck I'm trying to do. The default values of the columns on a couple of my tables need to be equal the result of some complicated calculations on other columns in other tables. My first thought is to simply have the column default value equal the result of a stored procedure. I would also have one or more of the parameters pulled from the columns in the calling table. I don't

Mapping fields in stored procedure to class properties with different names with Dapper

我与影子孤独终老i 提交于 2021-01-28 04:05:08
问题 I have this exert from a POCO class with many fields: public class Call { public int Id { get; set; } public string Customer { get; set; } public int StatusId { get; set; } public int UserAssignedToId { get; set; } public string UserAssignedToName { get; set; } } However my stored procedure returns different names to the properties above (in this case the Id is before: IdCall IdStatus IdUserAssignedTo This is the code I am using to execute the stored procedure: var call = conn.Query<Call>(

Mapping fields in stored procedure to class properties with different names with Dapper

亡梦爱人 提交于 2021-01-28 03:48:08
问题 I have this exert from a POCO class with many fields: public class Call { public int Id { get; set; } public string Customer { get; set; } public int StatusId { get; set; } public int UserAssignedToId { get; set; } public string UserAssignedToName { get; set; } } However my stored procedure returns different names to the properties above (in this case the Id is before: IdCall IdStatus IdUserAssignedTo This is the code I am using to execute the stored procedure: var call = conn.Query<Call>(

Can I check for uniqueness and write a document in a Cosmos DB stored procedure

社会主义新天地 提交于 2021-01-28 03:27:27
问题 I have a Cosmos DB stored procedure that creates a new document if it doesn't already exist and returns the existing or the new document. The procedure may be called from different processes. Can I be sure that the document is only created once even if several clients are trying to create it at the same time? function createIfNotExists(param1, param2) { var collection = getContext().getCollection(); // Query documents and take 1st item. var query = 'SELECT * FROM c WHERE c.Param1="' + param1

SQL Server 2016 Pivot

可紊 提交于 2021-01-28 03:23:01
问题 I have one question regarding sql (MS SQL 2016) and pivot functionality. First let me explain about the data structure. Examples of tbl_Preise . There are several prices ( Preis ) for each area ( Gebiet_von , Gebiet_bis ) in relays ( StaffelNr ). All connected to the same freight ( Fracht_id ). There can be a different number of relays for each freight. All of these relays repeat for each area, so i.e. there is one price for relay 1 in area 1800 - 1899 , but there is another price for relay 1