返回首页
We’re rewarding the question askers & reputations are being recalculated! Read more.

Questions tagged [tsql]

T-SQL (Transact Structured Query Language) is the extension of SQL functionality supported by Sybase ASE and Microsoft SQL Server. Do not use this tag for MySQL, PostgreSql, Oracle(Pl/SQL) related queries. Please note that SQL code which is being written using LINQ will not also be the part of this tag. This tag specifically created for advanced SQL programming using Microsoft SQL Server.

Filter by
Sorted by
Tagged with
-2
votes
0answers
22 views

SQL Restricting data range

The query below is supposed to show details for 2 types of products: DIS001 and DIS002. When DIS002, this should "reset" the query, so that it only shows DIS001 products which were sold after that the ...
0
votes
1answer
14 views

Getting error when trying to set SQL Server Backup with Date Filename

I use the following script to make a normal backup: USE SysproCompanyT GO EXEC('BACKUP DATABASE [Company] TO DISK = N''G:\SQLBackups\INSTANCE1\MonthEndBackup\Company\MonthEndBackup.bak'' WITH ...
0
votes
2answers
37 views

T-SQL : understand cursor for update of

I don't know what the role of for update of is in a cursor in T-SQL. I wrote this SQL statement: declare @id int, @nom varchar(30), @age int; declare cur_info cursor for select id, nom, age ...
-1
votes
1answer
30 views

SQL Server Filter data from 1 column and and create 4 new columns depended on the filter

SELECT[EntityContactPointID] ,[EntityKeyID] ,[ContactTypeLookupID] ,[Value] FROM [ASTRO_STAGE].[dbo].[tr_EntityContactPoints] EntityContactPointID EntityKeyID ContactTypeLookupID Value 1234 ...
0
votes
1answer
25 views

SUBSTRING / CHARINDEX ADVICE

I have the following field in my database: | FileName | +------------------+ | 4_20191118113041 | What I am trying to achieve is just return the 4, so anything before the underscore _. That ...
0
votes
2answers
34 views

How can i duplicate records with T-SQL and keep track of the progressive number?

How can I duplicate the records of table1 and store them in table2 along with the progressive number calculated from startnum and endnum? Thanks the first row must be duplicated in 4 records i.e num: ...
-1
votes
0answers
40 views

Creating/Droping tables in stored procedures [on hold]

Creating and dropping a table(not temp table) inside a stored procedure in SQL Server: Is this right? Will it lead to any security issues? What are the alternative ways to approach further?
1
vote
0answers
14 views

Send parameter in SQL OpenQuery with Recursive CTE

I have the following Recursive CTE which is used in an OpenQuery function in SQL I use OpenQuery to query a SQL Linked Server. The request does not work because the values from rows Line not transfer ....
0
votes
2answers
27 views

How to get all elements dynamically without knowing their number

I have an xml which might have several signatures elements. I don't know the number of signatures elements for each root but I need to group by this element so that I would get one row for each root ...
0
votes
2answers
39 views

How to opposite Select From a Bit Value in SQL without Use Case when [duplicate]

I Want to Select opposite Value of AbsenceStatus in tsql , AbsenceStatus DataType is Bit SELECT [Date], NOT(AbsenceStatus) As IsWorkday FROM tkp_DailyStatistics
0
votes
1answer
27 views

Execute STUFF return query string without storing into variable

I'm preparing select query using STUFF function. Given: DECLARE @GeoID VARCHAR(MAX) = '1,2,3,4' DECLARE @TableName VARCHAR(100) = 'Table1' SELECT STUFF((SELECT ' UNION ALL SELECT t.* FROM ['+@...
-1
votes
1answer
39 views

Add range to an array with JSON_MODIFY

I am trying to add an array to another array using JSON_MODIFY. The situation is, I have an array kind stored json data in database. It looks like this: declare @base nvarchar(max) = '[{"name":"base"}...
0
votes
0answers
14 views

Locking in context of the isolation levels

I'm trying to find a simple list and general explanation of which locks can be used in a specific isolation level. I mean I know in general: Read committed isolation level shared locks for reading ...
-1
votes
0answers
60 views

SQL - Is there a way of setting one variable to the value of another variable based off a table?

Is there a way of making one variable set to the value of another variable based off a lookup table in the database? I'm trying to generate a set of transactions into a table to be exported. I want ...
0
votes
0answers
11 views

Snapshot isolation behaviour. “Triggered” at first query?

I am doing some tests to try to understand how snapshot isolation works...and I do not. I have SET ALLOW_SNAPSHOT_ISOLATION ON in my db (not interested in READ_COMMITTED_SNAPSHOT atm). Then I do the ...
0
votes
0answers
27 views

N level managerName (Director name) using managerID for an employee [duplicate]

I have a table Employee with EmployeeID, Name, ManagerID(references EmployeeID) and RoleID I need to find the Direction name who is manager of manager, manager of manager of... till root user (who ...
-2
votes
0answers
33 views

Show Duplicate Data on the select

Declare @FromDate Nvarchar(8)='20191106', @ToDate Nvarchar(8)='20191106', @Store Nvarchar(100)='', @Subsidiary NVARCHAR(100)='', @HOCurrency BIT =0, @IncludeSales bit=1, @IncludeOrder bit=1, @...
-4
votes
1answer
46 views

Having a problem with altering a column type in a procedure

My task is to create a procedure that alters the column type based on the inputs. I tried looking on the internet for some help but didn't find any. I found the predefined function Alter Table but I ...
0
votes
1answer
31 views

Select Records against all months of a given year form one table with records from second table

I have two tables in my database: MembershipInstallments (ProjectId, AllotmentId, InstallmentId, EntryDate, AmountPaid) Memberships (ProjectId, AllotmentId, ClientId, ClientName, RegistrationNo) I ...
0
votes
2answers
39 views

Syntax Error when Using Case Statement (with Between before the statement)

I am using CASE statement in the where of a Select Statement SELECT * FROM [4c1917a7-2bab-4dbe-bb22-812a25a8930f] AS TP INNER JOIN TSaisie AS TS ON TP.[TInd_FK_ID] = TS.[TSai_FK_TInd_ID] WHERE ...
-1
votes
3answers
55 views

fiscal year sql server

I want to have a function that calculates the fiscal year. The fiscal year must begin on the first Monday in March. Thank you! example: CREATE FUNCTION dbo.fnc_FiscalYear( @AsOf DATETIME ) RETURNS ...
-2
votes
4answers
48 views

How to find RowID in SQL Server

If I use Row_Number(), then I need to use order by or partition by. That will not solve my issue here: Tab_1 (input table) Expected output (running total) In this case, if I write a query Select ...
0
votes
1answer
18 views

Value not Store in Dynamic SQL

I've different different tables to categorically store data and a log table where all the transactions log are recorded e.g. 1) VoucherNO, Add, ... 2) VoucherNO, Delete, .. After I backup the ...
0
votes
1answer
32 views

Must declare the table variable error while creating a TVP function

I have the following function created with a TVP. I am inserting data initially into the TVP and then selecting from it. CREATE FUNCTION [dbo].employees_data( @employeeIds NVARCHAR(MAX) ) RETURNS ...
0
votes
1answer
17 views

Join user-defined table type param to view

SQL Server 2012: I have a stored procedure with a parameter of user-defined table-type. To create its return rowset, the stored procedure selects from a view joined to the param table on a few ...
-1
votes
0answers
43 views

How to change SQLresult from vertical to horizontal ouput? [duplicate]

I need to change SQL result (SQL Server 2012) from vertical to horizontal output. How can I do it? From this SQL result: 139432 ABCD 12345 Qty1 1,00 139432 ABCD ...
0
votes
0answers
27 views

Looking for a Common Sub-string Aggregate function for MS TSQL

Given the following example. I'm looking for a clean solution that would return the common sub-string for group by queries. I.E. Min/Max/CSS (CommonSubString) enter image description here account | ...
-1
votes
0answers
38 views

Search a record by a range of Dates

A user enters search criteria from Screen like Names, ID or StartDate (when they enter a start date then it needs to retrieve every matched records from the given startDate till Current date). ...
0
votes
1answer
34 views

Converting VARCHAR to DATE in SSIS

I have a data flow task in a SSIS package that loads data into a table from a flat file. In the source data, there is a date column in the format DD/MM/YYYY, and I am trying to convert it to YYYY-MM-...
0
votes
3answers
51 views

How do I find out which users with a specific RoleID that's not been active within a time interval?

This query down below will tell me how many non-active users there's been during a timeframe. USE Database SELECT u.* FROM [dbo].[tbl_Users] u WHERE NOT EXISTS (SELECT 1 FROM [dbo].[...
0
votes
3answers
74 views

Converting a NVARCHAR into a UK date

I'm looking to convert a users input that will be a NVARCHAR to a UK date The user's input will always be a maximum of 6 digits. For example: 151119 (DDMMYY) --> 15NOV19 120119 (DDMMYY) --> ...
0
votes
1answer
39 views

SSMS - Trying to Bulk insert into a table but decimal field sometimes contains NA

I have tried to create a new table where the column is just varchar(100), but it gives the same conversion error. Most of the column consists of decimal numbers, but instead of putting null or leaving ...
0
votes
2answers
52 views

Left outer join on two columns only joining on one column [on hold]

I want this code to not just join on clientlocation, but also on clientdivision so it only matches if clientlocation is A and clientdivision is B. What am I doing wrong? left outer join EMEA_TRANS....
-2
votes
1answer
48 views

Stored procedure is not running due to “Incorrect syntax” error [on hold]

I am learning stored procedures with SQL Server 2018. The code below is not running due to this error: "Incorrect syntax near ' '." USE MyDatabase GO CREATE PROCEDURE spGetSongs AS Select Name,...
1
vote
1answer
52 views

Why do I get different results depending on the function I use? (SQL Server)

I've been tasked with creating a report for my company. The report is generated from the results returned by the Stored Procedure spGenerateReport, which has multiple filters. Inside the SP, this is ...
2
votes
1answer
37 views

Pivot dynamically depending on two columns

I have the following table which records the duration spent by a user for a chatroom : user_id | duration | errorscounts | week --------+------------------+----------------+-------- 1 ...
0
votes
1answer
45 views

how to use distinct and group with sql statement

i have created one query that is for parent summary list. here i just want to get records multiple time because mutiple entries to another table : here it is : ALTER PROCEDURE [dbo].[GetParentList](@...
0
votes
6answers
96 views

How can I get the last record for a given id in the fastest way? (MS SQL)

I would like to ask for your help. I have a table which looks like this: id | sequenceId --------------- 1 | 1 1 | 2 1 | 3 2 | 1 2 | 2 2 | 3 2 | 4 ... There are other columns as well but now it's ...
0
votes
2answers
34 views

How to create all possible combinations with splitted items in SQL?

I have data as in below delimited format data - '1A,2B,2A' expected output - is the combination with each element and the element itself OrderId combination 1 1A,2B 2 1A,2A 3 2B,...
0
votes
2answers
49 views

How to save more than 8000 characters in a SQL column

I have one column AgentName in a table Test which contains more characters. I am getting differences in length as shown below. If you see "C" , I have copied the output of @TMP and doing DataLength ...
-4
votes
0answers
41 views

Looking for a C# Example of a class or classes for storing the information in a SQL Index or Select Statement

I am working on a code generator. As part of that I want to represent the structure of a database. I have created classes for most of it and I am currently working on the Index class. I am ...
-2
votes
0answers
30 views

How to extract characters from a string stored as json data and place them in dynamic number of columns in SQL Server

I have a column of string in SQL Server that stores JSON data with all the braces and colons included. My problem is to extract all the key and value pairs and store them in separate columns with ...
1
vote
4answers
69 views

Split string of variable length, variable delimiters

Read the question posed here, but mine is a little more complicated. I have a string that is variable in length, and the delimiter can sometimes be two dashes, or sometimes it can be just one. Let's ...
0
votes
1answer
27 views

TSQL List Result based on date in name field minus GETDATE() function

In our QA environment we restore databases for Developers and then drop them if the restore was done > 30 days. The naming convention for these restored databases are MyCompany-...
0
votes
1answer
56 views

Querying items that have a date/time within the next 20 minutes

I am working on generating a notification when new items are added to a table. The table will be a filtered version of the [OrderTasks] Table. Using microsoft Power Automate i will generate a ...
0
votes
1answer
54 views

SQL - Summary of transactions - Calculate start end time of transactions based on column

I have a SQL table which holds transactions of products and cumulative total of packed products each minute from a machine. I'm trying to summarize this table (in a sql query) into product runs. The ...
0
votes
2answers
51 views

Can't access output variable in command text

Set cmd = Server.CreateObject("ADODB.Command") With cmd .ActiveConnection = db .CommandText = "SELECT @date = '2019-01-01'" .Parameters.Append(.CreateParameter("@date", adDBDate, ...
0
votes
0answers
27 views

If a user has access to “execute” an stored procedure, but does not have “insert” access to the specific table, will this stored procedure fail?

I'm having issues with this question. In my opinion, if the user has execute permission to the procedure, he doesn't need insert permission to the table. This is the stored procedure: USE [...
0
votes
0answers
50 views

Finding missing records in joined tables using ID and Dates in SQL?

I'm having trouble writing a check that will find missing records. My tables are Provider, ProviderRelationship, Agreement, and AgreementProvider. I need to find missing records where the Provider ...
0
votes
3answers
56 views

How do I find out which users that's not been active within a time interval

This script down below demonstrates how I find out which users that's been active within a time period. How do I figure which users that's not been active within this time interval? USE Database ...

返回首页
杏彩计划 杏彩官网 杏彩APP 杏彩走势图 杏彩下载 杏彩官方 杏彩网站 杏彩怎么玩 杏彩官方 杏彩靠谱吗 杏彩代理 杏彩骗局 杏彩投注 杏彩倍率 杏彩开奖 杏彩漏洞