Category "tsql"

SQL - Getting day for the whole week

I want to get the whole day of the week depend on the date, my query is working and getting the result that I want but when the date value is Sunday, result cha

Azure Synapse Serverless CETAS error "External table location is not valid"

I'm using Synapse Serverless Pool and get the following error trying to use CETAS Msg 15860, Level 16, State 5, Line 3 External table location path is not valid

tsql - How to convert multiples rows and columns into one row

id | acct_num | name | orderdt 1 1006A Joe Doe 1/1/2021 2 1006A Joe Doe 1/5/2021 EXPECTED OUTPUT id

SQL Server - Regex pattern match only alphanumeric characters

I have an nvarchar(50) column myCol with values like these 16-digit, alphanumeric values, starting with '0': 0b00d60b8d6cfb19, 0b00d60b8d6cfb05, 0b00d60b8d57a2b

How to insert multiple JSON rows into a T-SQL table

I am trying to insert following JSON document into T-SQL: { "GLDETAIL": { "RECORDNO": "264378-1756289-919567--accrual", "BATCH_DATE": "02/01/2

which is best using delete or truncate when i need to delete all data from table?

I work on sql server 2017 I need to delete all rows from table student_course but I don't know which is best for use delete from student_course OR truncate tab

How to get sum of multiple rows in a table dynamically

I am trying to get the total sum from columns of a specific data type(money) for multiple tables in a database. Currently I am able to get the list of columns f

Difference between Sqlcmd and Invoke-Sqlcmd

I am trying to learn Sqlcmd utility in PowerShell to run SQL queries, specifically for database administration. Using Version 15.0.1300.359 NT But I got confuse

Trouble inserting values into SQL table, values get mistaken for columns

I keep getting an exception that reads: "Invalid Column Name, 'IBM'." The error is happening at: "' + @ticker + '" even though @ticker is declared in VALUES.

Structure of T-SQL tables

I am switching from MySQL to SQL Server for a new job and I have encountered something I don't quite understand as I haven't encountered something like this bef

Is there a way to store full DDL of View or Procedure definition from another database in separate table

I'm trying to store DDLs of some views and stored procedures in a separate table in the Dump database. There are too many similar databases on the server. But s

Remove duplicates from SQL Window function

I'm trying to sum values inside a window function but I can't figure out have to prevent summing duplicates. Below is a snippet of the results I have right now.

Pivot two columns

I have data that looks likes: stu_id course_name staff_name 1 Economics - 3 Kuzma, Brian 1 History Hulings, Kreg 1 IHS IB Lit of Americ Duncan, Amy 2 Marine Bi

How to replace starting two digit (00) with blank space in T-SQL?

I have a table where as codes are present in the form of 78,7244,d345 by default few records are found where the codes are start with 0072 . I have to delete st

How can I get the output of the query below into one result set in t-sql?

I only have only "read" permissions to the database. I am trying to pull data out of several tables with the same fields. I am pulling the table names from th

Cannot initialize the data source object of OLE DB provider "OraOLEDB.Oracle" for linked server

I am trying to query data from linked server. It is giving me the following error: TNS:listener does not currently know of service requested in connect descrip

SQL Server - Combine two select queries

I have two tables, Semester1 and Semester2. Semester1: StudentId SubjectId abc sub1 def sub1 ghi sub1 Semester2: StudentId SubjectId abc changedSub1 def sub1

How to remove the first word from a large string

I want to remove the first word from a large string in SQL Server. Input string: 931078027 BP 16:20:0:13 25 BAG 'B' CLASS Desired output: BP 16:20:0:13 25 BAG

How to validate the date in a varchar column in SQL Server

I have a staging table which contains all varchar columns. I want to validate a date stored in the data column. Since my staging table contains all varchar colu

T-SQL - search in filtered JSON array

SQL Server 2017. Table OrderData has column DataProperties where JSON is stored. JSON example stored there: { "Input": { "OrderId": "abc", "Data": [