Category "sql-server"

SQL Server - Order by defined hierarchy

I have, for example, the following table: Client ID Function 1234 RE 1234 WE 1234 SP 1234 AG 6789 AG 6789 WE And I want to get only 1 client ID but that obeys

How to proxy MSSQL connections over TCP proxy with cached Kerberos credential?

I need to proxy MSSQL connections over a TCP proxy using cached kerberos credentials. The idea is to authenticate against the database with kerberos, cache the

Convert yyyymmdd string to yyyy-mm-dd date datatype ignoring the hrs,secs etc.... in SSIS

When I tried to convert the yyyymmdd (DT_Wtsr, string, len 8) to DATE datatype (yyyy-mm-hh) using the below expression: (DB_DATE)(SUBSTRING([Column],1,4) + "-"

How can I Insert multiple rows with one query

I made a code allowing me to GET data from an API and insert it into a database. But I encounter a problem my api contains about 20 million data and to insert e

Update foreign key field in table to primary key values in another table

After adding SID to the TRANSACTIONS table, I need to update SID column in TRANSACTIONS based off STORE_NBR in the STORES table. Basically, I want to update the

How to install SQL Server PowerShell module on my company's server

Environment: Windows 2016 Server Standard PowerShell 5 Has Internet connection Running PowerShell as administrator JFrog is something new we're implementing but

How to prevent SQL Server from stripping leading zeros when importing data

A data file is imported to a SQL Server table. One of the columns in data file is of text data type with values in this column to be integers only. The correspo

How to add a leading 0 in sql-server [duplicate]

I have to add a leading 0 in a column called houses, where it is a unique list of 3 digits, but I wanted have to add a leading 0 to it -->

How to prevent SQL Server from stripping leading zeros when importing data

A data file is imported to a SQL Server table. One of the columns in data file is of text data type with values in this column to be integers only. The correspo

Get Hieararchical data as JSON from SQL Server

I have following table: Id HieararchyId Name 1 / MHz 2 /1/ Finance 3 /1/ IT 4 /1/3/ Software Development 5 /1/3/ QA 6 /1/2/ Accountant and I want to get data

Get Hieararchical data as JSON from SQL Server

I have following table: Id HieararchyId Name 1 / MHz 2 /1/ Finance 3 /1/ IT 4 /1/3/ Software Development 5 /1/3/ QA 6 /1/2/ Accountant and I want to get data

Adventureworks exercises SQL Server

Using the SalesOrderHeader and SalesTerritory tables, write a query to calculate the number of transactions and total monthly amount per territory for each of

deleting specific duplicate and original entries in a table based on date

i have a table called "main" which has 4 columns, ID, name, DateID and Sign. i want to create a query that will delete entries in this table if there is the sa

Calculating Cost of Sales in SQL using FIFO method

From a stock transaction table I've created following sorted view table to be ready for FIFO: rowN date_ stockCode sign_ amount unitPrice 1 '2022-01-20' ABC in

Use Single Button to select Multi option and Update or Insert On Ms Sql Server

Multi select option list image I Use a multi select option list and create a save button. write a query like that is INSERT and UPDATE same action occur on sing

return value cannot be used in this context at begin

Create function getallWeekDayorWeekends ( @givenDate as date, @choice as int ) RETURNS Table as BEGIN if(@choice = 1) return (SELECT cast(DATEADD(DA

How to connect to Docker container with localhost instead of 127.0.0.1

I am running a mcr.microsoft.com/mssql/server docker container for local development that works perfectly on one machine. But on my laptop the container is some

How primary key in one table connect to other table with the same primary key?

How primary key in one table connect to another table with the same primary key? I am trying to make it like this, which those two primary key in the table of C

State count and uf sql

I want to count the employees, by state and UF, but when I run my code it counts by department: CREATE PROCEDURE SP_DATA_MART_CARGA AS IF NOT EXISTS(SELECT *

Pass parameter from Excel to SQL in PowerQuery

I want to set local variables or pass parameters from Excel to SQL. I've found similar questions, but all referred to old versions of Excel and/or the answers s