tsql

Waiting for DB restore to finish using sqlalchemy on SQL Server 2008

六月ゝ 毕业季﹏ 提交于 2020-08-23 07:33:38
问题 I'm trying to automate my db restores during development, using TSQL on SQL Server 2008, using sqlalchemy with pyodbc as a transport. The command I'm executing is: """CREATE DATABASE dbname restore database dbname FROM DISK='C:\Backups\dbname.bak' WITH REPLACE,MOVE 'dbname_data' TO 'C:\Databases\dbname_data.mdf',MOVE 'dbname_log' TO 'C:\Databases\dbname_log.ldf'""" Unfortunately, the in SQL Management Studio, after the code has run, I see that the DB remains in state "Restoring...". If I

Escaping characters in T-SQL OPENJSON queries

牧云@^-^@ 提交于 2020-08-23 03:44:42
问题 I have the following JSON Data DECLARE @jsonData NVARCHAR(MAX) SET @jsonData = '{ "insertions":[ { "id":"58735A79-DEA8-462B-B3EB-C2797CA9D44E", "last-modified":"2017-08-08 13:07:32", "label":"HelloWorld1" }, { "id":"00565BCD-4240-46CF-A48F-849CB5A8114F", "last-modified":"2017-08-08 13:11:38", "label":"HelloWorld12" } ] }' And trying to perform a select from it: SELECT * FROM OPENJSON(JSON_QUERY(@jsonData,'$.insertions')) WITH (uuid UNIQUEIDENTIFIER '$.id', modified DATETIME '$.last-modified',

How to view the stored procedure code in SQL Server Management Studio

怎甘沉沦 提交于 2020-08-20 18:28:06
问题 I am new to SQL Server. I am logged into my database through SQL Server Management Studio. I have a list of stored procedures. How do I view the stored procedure code? Right clicking on the stored procedure does not have any option like view contents of stored procedure . Thanks. 回答1: right click on the stored proc and select script stored procedure as CREATE to New Query Editor Window/Clipboard/File you can also do Modify when you right click on the name If you want to more than 1 proc at

How to read field name with space in Json using OPENJSON in SQL Server 2016

不羁的心 提交于 2020-08-20 03:59:35
问题 How can I read value from json file in that field name contains space using OPENJSON in Sql Server 2016 . See the below code: DECLARE @json NVARCHAR(MAX) SET @json = N'{ "full name" : "Jayesh Tank"}'; SELECT * FROM OPENJSON(@json) WITH ( [name] [varchar](60) '$.full name') Also another sample code in that space is after field name. SET @json = N'{ "name " : "abc"}'; SELECT * FROM OPENJSON(@json) WITH ( [name] [varchar](60) '$.name') '$.name' will return null.Is there way to read this value?

Query XML data for information based on a sibling value

醉酒当歌 提交于 2020-08-11 01:50:02
问题 I have the following XML data, which I have zero control over. Note that it's basically a collection of property groups. I need to select the value of one property where the value of another property is 'true'. The problem is, there's nothing to group on, and I cannot figure out how to associate things correctly. Here's the XML Data, and the query I came up with so far: DECLARE @xml xml = ' <Container> <Collection> <ItemName>SomeItem</ItemName> <IsDeletable>true</IsDeletable> <IsPersisted

Query XML data for information based on a sibling value

只谈情不闲聊 提交于 2020-08-11 01:49:11
问题 I have the following XML data, which I have zero control over. Note that it's basically a collection of property groups. I need to select the value of one property where the value of another property is 'true'. The problem is, there's nothing to group on, and I cannot figure out how to associate things correctly. Here's the XML Data, and the query I came up with so far: DECLARE @xml xml = ' <Container> <Collection> <ItemName>SomeItem</ItemName> <IsDeletable>true</IsDeletable> <IsPersisted

How to Build select Query split Temp Value to two column one Per Number And Another to Text when Flag Allow 1?

佐手、 提交于 2020-08-10 23:24:50
问题 I work on a query for SQL Server 2012. I have an issue: I can't build select Query split Column Temp value to two Column When row in the temp table #nonparametric has the flag Allow = 1, it must split column Temp value from #nonparametric to two column when the flag Allow = 1 . suppose column Temp value has value 50.40 kg it must split to two column First column with number so it will have 50.40 and it will be same Name as Parametric . Second column with Text so it will have kg and it will be

Randomize part of select from CTE output

ぃ、小莉子 提交于 2020-08-09 09:13:07
问题 In this question @GordonLinoff provided a solution (recursive common table expression) to my initial question. This is a follow-up question. Initial question : How can I loop through registrations until a certain amount (sum) of AmountPersons was reached and if the next AmountPersons was too high to be invited check the AmountPersons of the next row to see if it would fit? Please check the initial question via the link above to get the full picture. New situation : First we have 20 available

Not In operator eliminates NULL values rows in a table

孤街醉人 提交于 2020-08-08 05:28:26
问题 I would like to retrieve all rows with values except 1,2,3,4,5 in my COLUMNA in TABLEA . SELECT * FROM TABLEA WHERE COLUMNA NOT IN (1,2,3,4,5) But this eliminates the rows with NULL values in COLUMNA too. I don't want to eliminate NULL values rows and would like to include those rows in the resultset. Alternatively, I can try below query for the same SELECT * FROM TABLEA WHERE COLUMNA NOT IN (1,2,3,4,5) OR COLUMNA IS NULL. But I would like to know, why is it necessary to add this OR condition