Questions tagged [sql-server]

Microsoft SQL Server is a relational database management system (RDBMS). Use this tag for all Microsoft SQL Server editions including Compact, Express, Azure, Fast-track, APS (formerly PDW) and Azure SQL DW. Do not use this tag for other types of DBMS (MySQL, PostgreSQL, Oracle, etc.). Do not use this tag for issues on software and mobile development, unless it is directly related to the database.

Filter by
Sorted by
Tagged with
0 votes
0 answers
9 views

SQL: Using FIRST_VALUE

Here is some example data: create table #Baseline (Document varchar(40), Type varchar(10), Location int) insert into #Baseline values ('Pump Telemetry', 'None', NULL), ('Clinical Documentation', '...
jw11432's user avatar
  • 549
0 votes
0 answers
12 views

In CDC, Not able to read the data from CDC function but the DB_Owner can read it what permission should I get

In CDC, Not able to read the data from CDC function but any user in DB_Owner can read it what permission should I get ? whenever I call this function I get empty records cdc....
JPNN's user avatar
  • 383
0 votes
2 answers
58 views

Performance issue in stored procedure

I need to improve performance of my stored procedure. Please find my stored procedure below which works fine, but it takes more than 5 minutes for some time not always to get the result due to that it'...
user17824023's user avatar
-2 votes
0 answers
36 views

Is being able to refer to a CTE in a FROM-less UPDATE clause undocumented behaviour?

The syntax for the first part of UPDATE is documented as follows UPDATE [ TOP ( expression ) [ PERCENT ] ] { { table_alias | <object> | rowset_function_limited [ WITH ( ...
J. Mini's user avatar
  • 2,004
-1 votes
0 answers
28 views

SQL Trigger for updating 2 table does not work [closed]

I have 2 table product and stock_in, whenever table stock_in is being inserted with data, column quantity_in in table product is updated with the same value of column quantity in table stock_in. Here'...
Exal's user avatar
  • 1
-1 votes
3 answers
45 views

SQL Server - how to delete all duplicate employee records excluding the most recent record for each employee [duplicate]

[Microsoft SQL Server 2019 (RTM-CU18) (KB5017593) - 15.0.4261.1 (X64)] I have this query to find all duplicate employee records. A duplicate record is a record with the same EmployeeID as another ...
Bushmatic's user avatar
0 votes
1 answer
32 views

Cannot connect to SQL Server database - Cucumber, mssql nodejs, typescript

I am trying to connect to a SQL Server database but I got an error and it says nothing to me... This is my Db connection file: import { error } from 'console' import sql from 'mssql' const sqlConfig =...
joanna's user avatar
  • 1
-1 votes
0 answers
22 views

How to decrement the value of an index by 1 within SMSS?

I'm working on a project for university that involves creating a school management System in C#, and there's a lesson schedule that is meant to show what class has what lessons in every given day and ...
NoBody134's user avatar
-1 votes
0 answers
29 views

MERGE SQL Server stored procedure

I'm trying to optimize the performance of a complex stored procedure and one of the available options is to use the merge instead of multiple insert statements, but I can't figure out how to do it if ...
Sob.Ruba's user avatar
-3 votes
1 answer
40 views

SQL Developer - Changes on tables DO NOT show

CREATE TABLE GRADE( COURSE_CODE VARCHAR(4) NOT NULL, STUDENT_NO VARCHAR(7) NOT NULL, GRADE_NO NUMBER(3) NOT NULL, PRIMARY KEY (STUDENT_NO, COURSE_CODE), FOREIGN KEY (STUDENT_NO) ...
mattia's user avatar
  • 5
-1 votes
1 answer
56 views

SQL data column merge together if value exists already

SQL Server screenshot SQL SELECT [Order Number] ,[Date] ,[Name] ,[Email] ,[Return ID] ,[Createddateandtime] ,[Item Quantity] FROM [PowerBIXPO].[dbo].[ReturnHeader] ...
Bernard's user avatar
0 votes
0 answers
50 views

ASP.NET SQL Server login inconsistency [closed]

I have an ASP.NET API server that gets some data from a local Microsoft SQL Server to server client API requests. If the server has been unable to login to SQL Server, then this error is also sent ...
SKB_BGPL's user avatar
-1 votes
0 answers
34 views

SQL Server 2022 Clustered ColumnStore Index with Order doesn't seem to create order

I have a microservice that writes data to an sql server 2022 on a clustered columnstore index . After table is created with EF Core migrations and before writing anything to it I run CREATE CLUSTERED ...
pantonis's user avatar
  • 5,637
0 votes
2 answers
18 views

Select data from one table depending on the results of another select SQL Server

I have two tables that I need to compare to find records that are not in one table. My SQL so far is, SELECT ORD_NAME FROM ERP_IMPORT_COMP EXCEPT SELECT NAME FROM OR_ORDER This returns the ORD_NAME's ...
tt_time's user avatar
  • 23
-2 votes
0 answers
68 views

How to substitute a table name from another query

I get a list of tables from another query in SQL Server: select [Sch].[name] + '.' + [Tab].[name] from ARP.sys.tables as [Tab] inner join ARP.sys.columns as [Col] on [Tab].[...
Marcus Still's user avatar
0 votes
2 answers
46 views

Declaring a query string as a variable - how do I?

I would like to create a partial SQL query as a variable and re-use this query string across multiple databases as per below. I have about 30 databases and would ideally like to swop in and out the ...
VGA's user avatar
  • 31
-2 votes
0 answers
27 views

sp_get_query_template doesn't work with ODBC timestamp

I have the following query: SELECT COUNT(*) FROM ( SELECT DISTINCT USER_NAME FROM LICENSE WHERE RESTRICTED_USE = 'T' AND ALLOCATED = 'T' UNION ALL SELECT USER_NAME FROM ...
Fausto Galati's user avatar
-5 votes
1 answer
65 views

Separate strings and select from another table

I want to separate strings from table1.data than select from table2.country. (SQL server 15.04312.2) Table1 ID DATA a 6,2 s 5,6,9 d 3,2,1 x 4,8 z 3,7 Table2 ID Country 1 country1 2 country2 ...
Dashi's user avatar
  • 3
-1 votes
1 answer
69 views

Multiple table-based replacement in a SQL function

I need to create a function that performs multiple replacements in a string based on a lookup table. However, the result is always the last replacement as if the previous replacements don't happen. ...
ulu's user avatar
  • 5,890
0 votes
0 answers
64 views

Inserting timestamp into datetime2 columns

I'm working in Azure Synapse Dataflows, and want to insert a date column into our SQL DWH table, where the column is defined as a datetime2(7) column. In the SQL Server table, the values of the ...
tamiboy777's user avatar
-2 votes
1 answer
38 views

SQL server 2019 how to search for specific column value in sql from all tables without using cursor?

I want to list all tables and columns where any column value starts with http.I already did it by using cursor ,but cursor is very slow.Also dynamic query exceeds the length and throws the error.Is ...
Swarel Jadhav's user avatar
-2 votes
0 answers
43 views

Case expression to compare against NULL [closed]

I want to create a flag based on a value present in a column. If the column value is null then 0 else 1. I also rewrote this in a statement format for better readability. If the column value is null ...
tunnelview's user avatar
-2 votes
0 answers
41 views

SQL Using Outer Apply Join - Improve SQL performance [closed]

How to improve performance of my stored procedure? This is my stored procedure which works fine, but it takes more than 5 minutes to get the result due to that its causing timeout from API. Note - @...
kumas srunk's user avatar
-1 votes
1 answer
48 views

How to calculate three three shifts in 24 hours in T-SQL

I need to calculate three shifts in 24 hours. I wrote a case expression to get the three shifts. I am getting morning and evening shift but getting null values for night shift, i.e. the time between ...
tunnelview's user avatar
0 votes
1 answer
46 views

Count rows by monthend - year to date falling between two dates

I'm trying to create a query that can return counts of rows that fall between two dates as of the last day of the month prior and a count for the current month (MTD) at the time the query is run. For ...
Shadrack's user avatar
0 votes
0 answers
30 views

Row changed between retrieve and update. Powerbuilder Error

I have a Datawindow called dw_1 with Two tables Table1 Left Join Table2. I am retrieving the dw_1 with some retrieval arguments (For Eg. 100 rows retrieved), after that I am Modifying some 10 rows in ...
Gokul Kannan's user avatar
0 votes
0 answers
33 views

RunLinuxScript from SQL Server on Linux server using JOB

Product: Microsoft SQL Server Operating system: Ubuntu (20.04) Platform: Linux I am moving from SQL over Windows to SQL on Linux. Previously I use @subsystem = N'CMDEXEC' when try ...
user1932675's user avatar
0 votes
0 answers
16 views

Does SQL Server Migration Assistant (SSMA) link one database to another permanently (Linked Server) or is it a one time migration?

I read about the possibility of using SSMA to migrate tables in Oracle to a SQL Server Instance. It looks pretty easy, and robust. However my issue is that I need the connection to be permanent, for ...
moltke_colombia's user avatar
-4 votes
1 answer
55 views

SQL query returns only a portion of expected results [closed]

I would like to understand why this code only returns 35 results, when the Customer database table (with column EmailAddress) has well over 35 rows. I received full marks for this assignment, but it ...
Kathryn B Araya's user avatar
-1 votes
0 answers
22 views

Adding a new unique column with null values to an existing table [duplicate]

I have a table in my database with the name Inventory. This table is already existed and has records in it previously. I would like to add a new column namely "Barcode" (varchar 20) to ...
TuncayCoban's user avatar
0 votes
0 answers
16 views

Measure Counts Doubled in SSAS based on where dimension is referenced in MDX statement

I updated and reprocessed a cube this weekend. It seemed that everything went fine since everything processesed as expected. However, this morning it seems like the data for one Measure, for one ...
user8675309's user avatar
0 votes
1 answer
50 views

T-SQL query to find all user IDs that worked all specified dates

I have a table designed like this (simple example): WorkRecords (UserID, DateWorked) UserID DateWorked ----------- ----------------- 111111 '2023/09/01' 222222 '2023/09/...
thekonger's user avatar
  • 179
0 votes
1 answer
44 views

Discovering unused tables in a SQL Server database

I was assigned the task of going through the tables in our database and writing a query to figure out which tables are not used anymore by any of our procedures. Here are some starting points I have ...
Zachary Golla's user avatar
-2 votes
0 answers
26 views

Unable to connect to Microsoft Dataverse as a Linked Server

I require assistance in establishing a linked server connection from an on-premises server to Dynamics 365 Dataverse. I attempted to follow this tutorial: Connect to Microsoft Dataverse as a Linked ...
Bender.'s user avatar
  • 67
-1 votes
0 answers
24 views

Cant connect to Microsoft SQL Server in Anypoint Studio

I try to connect from Anypoint Studio to Microsoft SQL Server but I found this error: This is my config: <db:config name="Database_Config" doc:name="Database Config" doc:id=&...
TwinZaia's user avatar
-1 votes
1 answer
61 views

Connecting to Azure SQL Server Fails

I created a Azure SQL Database Server as shown in the image below with only microsoft-entra authentication enabled, later when i try to connect to it through SSMS, it gives me the error on selecting ...
Ritwik Das's user avatar
-3 votes
0 answers
23 views

Typeorm Decimal Data Type MSSQL Error - Wrong number after inserting when precision is > 2

I use TypeOrm in connection with MSSQL. When I create an entity with the type "Decimal" and define Precision and Scale, I get wrong values in the database if the Scale is greater than 2. For ...
EcoFa's user avatar
  • 1
-2 votes
2 answers
34 views

SQL sum the count of populated fields grouped by another field

How do I sum the count of populated fields. An example of the data. The desired output would be. This is what I have managed so far. select m.project_ref, ( select count(*) ...
Ian's user avatar
  • 107
-1 votes
0 answers
36 views

Is there any way to migrate(downgrade) from sql server 2022 to sql server 2017

I know that migrations allow you to update from lower to higher version of mssql server, but is there any way to go backwards? I've tried to use backup files but this doesn't seem to work or maybe I'm ...
Bannyk's user avatar
  • 1
-3 votes
1 answer
64 views

Data type convert using Derived Column

I used derive column to convert date from csv to DB type but I got this error message This is the date type on csv. This is the format This is the table on db I have tried to use Derived Column ...
Safouen Bensidhom's user avatar
0 votes
1 answer
36 views

Supress number version from InstanceID

I am installing SQL SERVER 2022 from command line with this command: SETUP.exe /IACCEPTPYTHONLICENSETERMS="False" /ACTION="Install" /ROLE="AllFeatures_WithDefaults" /...
Mazinger's user avatar
  • 641
-1 votes
1 answer
63 views

Is it really a bad practice to use SQL from client side application (where the end-client own the database) [closed]

My company make Point Of Sell and Accounting systems. each client (being a restaurant or supermarket) have a server machine on the local network, that have MS SQL, so all cashiers applications ...
Hamza Ku's user avatar
0 votes
1 answer
62 views

Replacing values in a table with values in a look up table

I have data stored in a table that requires specific values to be removed so it can be shared more widely. The data that needs to be removed will have a key as below: Data Table Statement Answer ...
Michael637352's user avatar
-3 votes
0 answers
31 views

Folder MSSQL11.MSSQLSERVER doesn't exist in C:\Program Files\Microsoft SQL Server [closed]

I have SQL Server Management Studio 19. I want to create a backup. I am following instructions that tell me to find the MSSQL11.MSSQLSERVER folder, but that doesn't exist in C:\Program Files\Microsoft ...
Diana's user avatar
  • 1
-1 votes
1 answer
50 views

SqlClient ignores User Id in connection string [closed]

I have a C# application in which I use EntityFramework. In my App.config file I got a Connection String, which contains server, database, User ID password and so forth. But when I run my application ...
Martin M's user avatar
  • 463
0 votes
0 answers
22 views

Pyodbc not running in Docker

I am trying to deploy a docker image which runs Python/Django app but I am getting the following error: f"DRIVER={mssql_driver};SERVER={mssql_server};DATABASE={mssql_database};UID={mssql_user};...
Alex T's user avatar
  • 3,581
-1 votes
0 answers
28 views

SQL Integration Services not showing in SSMS [closed]

I have SQL server 2019 When I try to connect SQL server Integration service in SSMS under local services not showing it. But in SQL server Configuration manager I can see integration services are ...
Imesha Anuruddha's user avatar
-3 votes
2 answers
49 views

Proportionally split a field across rows

I have a field that is doubling a value by populating it in both rows for the date/location/product/company id. The lost Sales is coming through into both rows, but it is actually the total for both. ...
jt721's user avatar
  • 11
-2 votes
0 answers
16 views

SCD2 implementation for datawarehouse tables [closed]

I have 3181 tables in my staging database(i.e Azure SQL database) I want to do SCD2 implementation for all the tables in my target azure SQL database (i.e data warehouse) by using azure data factory. ...
SUSHANTH SANJU's user avatar
0 votes
0 answers
24 views

Getting SQL_HANDLE_HENV failed error only after a disconnection

I found other similar questions with the same error (i.e. this and this) but apparently all of them are related to a wrong library / configuration since the users cannot connect to the database at all....
Mark's user avatar
  • 4,422

1
2 3 4 5
6647