tsql

How to add HIDDEN property on column?

蓝咒 提交于 2021-02-16 13:37:45
问题 When temporal table is created, we need to defined start and end date time columns which can be hidden - not visible in SELECT * or INSERT without columns . I want to add one more column, which will contain information about the user who has commit the change. The issue is, I am getting the following error: Msg 13735, Level 16, State 1, Line 10 Cannot alter HIDDEN attribute on column 'UserID' in table 'GK' because this column is not a generated always column. Here is the code: DROP TABLE IF

SQL variable to hold list of integers

无人久伴 提交于 2021-02-15 08:12:16
问题 I'm trying to debug someone else's SQL reports and have placed the underlying reports query into a query windows of SQL 2012. One of the parameters the report asks for is a list of integers. This is achieved on the report through a multi-select drop down box. The report's underlying query uses this integer list in the where clause e.g. select * from TabA where TabA.ID in (@listOfIDs) I don't want to modify the query I'm debugging but I can't figure out how to create a variable on the SQL

SQL variable to hold list of integers

一个人想着一个人 提交于 2021-02-15 08:03:25
问题 I'm trying to debug someone else's SQL reports and have placed the underlying reports query into a query windows of SQL 2012. One of the parameters the report asks for is a list of integers. This is achieved on the report through a multi-select drop down box. The report's underlying query uses this integer list in the where clause e.g. select * from TabA where TabA.ID in (@listOfIDs) I don't want to modify the query I'm debugging but I can't figure out how to create a variable on the SQL

SQL join on string_split values

眉间皱痕 提交于 2021-02-11 16:56:56
问题 So, I have a column value something like this: 1,15,32,64 And another table (called infoTable) where the identifier and text is in seperate columns. What would be the best way to get the Data of the infoTable into an select from the mainTable ? I've thought about string_split but cant find anything on how i should start with that. Im currently using MS SQL Server Manager Studio. 回答1: below is the join select i.* FROM infoTable i INNER JOIN string_split('1,15,32,64',',') sp on i.columname=sp

Getting depth-first traversal insted of breadth first in T-SQL

限于喜欢 提交于 2021-02-11 16:55:55
问题 I have the following T-SQL function: https://gist.github.com/cwattengard/11365802 This returns data in a breadth-first traversal. Is there a simple way to make this function return its data in a depth-first traversal? I have a treeview-component that excpects this (legacy system). I already have a similar stored procedure that returns the tree in a depth-first traversal, but it's using cursors and is really slow. (6-7 seconds as opposed to this function that takes less than a second on the

SQL Help : Exception report - extended

那年仲夏 提交于 2021-02-11 15:00:42
问题 Extend on: SQL help - exception report In my previous post I requested hep for: I have: a company table (CompanyID, CompanyName), Date table (Datekey int, date, isTradingHoliday 0/1), Fact table (id, datekey, companyID, StockClosePrice) I need help to write a query to find for which days and for which companies I don't have data in the fact table. SQL below does the job select c.*, d.* from companies c cross join dates d where d.isTradingHoliday = 0 and not exists (select 1 from facts f where

Function to convert from latitude and longitude to UTM X and UTM Y coordinate in SQL Server

最后都变了- 提交于 2021-02-11 14:46:55
问题 I need to create a function that converts longitude and latitude to UTM X and UTM Y coordinates in SQL Server. When the user provides longitude and latitude, the function should convert that information to UTM X and UTM Y coordinates. 回答1: I would recommend using CoordinateSharp which is available as a NuGet package: https://github.com/Tronald/CoordinateSharp It has support for UTM 回答2: I have developed a library in .NET to be called from transact sql Converts WGS84/UTM coordinates to

Sql Server Nested Inserts possible

若如初见. 提交于 2021-02-11 14:01:35
问题 I have data in flatfile structure which I need to Insert into two tables. The structure is: ID FName SName DOB Response1 Description1 Response2 Description2 Response3 Description3 3 Bill John 01/01 Yes Fault NULL NULL NULL NULL 4 Cat Bill 01/01 Yes FaultX Emer FaultYX Zeber Nuhgt The two tables where the above data will be inserted: Persons table -> ID, FName, SName, DOB PersonsRelations table -> ID, Response, Description where Response1, 2 etc is NOT NULL. I have started the tsql query but

Sql Server Nested Inserts possible

↘锁芯ラ 提交于 2021-02-11 13:57:41
问题 I have data in flatfile structure which I need to Insert into two tables. The structure is: ID FName SName DOB Response1 Description1 Response2 Description2 Response3 Description3 3 Bill John 01/01 Yes Fault NULL NULL NULL NULL 4 Cat Bill 01/01 Yes FaultX Emer FaultYX Zeber Nuhgt The two tables where the above data will be inserted: Persons table -> ID, FName, SName, DOB PersonsRelations table -> ID, Response, Description where Response1, 2 etc is NOT NULL. I have started the tsql query but

Count SQL Server User Created Functions based on Type

安稳与你 提交于 2021-02-11 13:55:49
问题 I can count total user created functions in SQL Server using SELECT COUNT(*) FROM information_schema.routines WHERE routine_type = 'FUNCTION' But this returns all functions whether it be a scalar-valued function, an inline function or a table-valued function Is there a way to obtain a count specific to the type of function? E.g. count inline functions only? 回答1: This distinction you are after is specific to SQL Server and probably not covered by the information_schema standard. You need to