tsql

Issues encountered with dynamic SQL

爱⌒轻易说出口 提交于 2020-06-01 07:36:06
问题 ALTER PROCEDURE [dbo].[Create_Subjects] @Subj_ID nvarchar(9) AS DECLARE @First3Digits nvarchar(3); DECLARE @Result int; DECLARE @Sql nvarchar(max) -- Fetching the fiest 3 digits of the subject SET @First3Digits = SUBSTRING(@Subj_ID,1,3); -- Check if view is present or not IF EXISTS (SELECT 1 FROM sys.views WHERE Name = @First3Digits) BEGIN SET @Sql = 'select @Result = case when exists (select 1 from dbo.' + quotename(@First3Digits) + ' where SubjectName = ''' + @Subj_ID + ''') then 1 else 0

SQL Server null table join

拜拜、爱过 提交于 2020-05-31 04:13:00
问题 I have two tables one of it is LEAGUE, another is MATCH , in MATCH table there is a column as refLeague now I want to get total matches of week For example Id TotalMatches -- ------------ 1 12 2 0 3 6 If there is no match, I want to write 0 as table SELECT l.Id ,COUNT(m.Id) as TotalMatches FROM LEAGUE l LEFT JOIN MATCH m ON l.Id = m.refLeauge WHERE m.MatchDate >= DATEADD(dd, DATEDIFF(dd, 1, GETDATE()) / 7 * 7 + 1, 0) AND m.MatchDate < DATEADD(dd, DATEDIFF(dd, -6, GETDATE())/7 * 7 + 1, 0) AND

SQL Server null table join

放肆的年华 提交于 2020-05-31 04:11:29
问题 I have two tables one of it is LEAGUE, another is MATCH , in MATCH table there is a column as refLeague now I want to get total matches of week For example Id TotalMatches -- ------------ 1 12 2 0 3 6 If there is no match, I want to write 0 as table SELECT l.Id ,COUNT(m.Id) as TotalMatches FROM LEAGUE l LEFT JOIN MATCH m ON l.Id = m.refLeauge WHERE m.MatchDate >= DATEADD(dd, DATEDIFF(dd, 1, GETDATE()) / 7 * 7 + 1, 0) AND m.MatchDate < DATEADD(dd, DATEDIFF(dd, -6, GETDATE())/7 * 7 + 1, 0) AND

efficient way to transform XML document into tabular dataset in SQL because cross apply xml query performs exponentially worse as xml grows

断了今生、忘了曾经 提交于 2020-05-30 21:00:34
问题 I have a big size XML document (50.000-100,000) that needs to be parsed on Azure SQL that looks like this: <?xml version="1.0" encoding="UTF-8"?> <covid-19 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://covid-19.iss.it/XMLSchema/0.1/"> <pazienti> <paziente> <codiceRegionalePaziente>0123456789</codiceRegionalePaziente> <codiceFiscale/> <nome>nomeBulk01</nome> <cognome>cognomeBulk01</cognome> <dataNascita>1989-12-31</dataNascita> <sesso>F</sesso> <nazionalita>380<

efficient way to transform XML document into tabular dataset in SQL because cross apply xml query performs exponentially worse as xml grows

こ雲淡風輕ζ 提交于 2020-05-30 20:57:58
问题 I have a big size XML document (50.000-100,000) that needs to be parsed on Azure SQL that looks like this: <?xml version="1.0" encoding="UTF-8"?> <covid-19 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://covid-19.iss.it/XMLSchema/0.1/"> <pazienti> <paziente> <codiceRegionalePaziente>0123456789</codiceRegionalePaziente> <codiceFiscale/> <nome>nomeBulk01</nome> <cognome>cognomeBulk01</cognome> <dataNascita>1989-12-31</dataNascita> <sesso>F</sesso> <nazionalita>380<

efficient way to transform XML document into tabular dataset in SQL because cross apply xml query performs exponentially worse as xml grows

一世执手 提交于 2020-05-30 20:57:35
问题 I have a big size XML document (50.000-100,000) that needs to be parsed on Azure SQL that looks like this: <?xml version="1.0" encoding="UTF-8"?> <covid-19 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://covid-19.iss.it/XMLSchema/0.1/"> <pazienti> <paziente> <codiceRegionalePaziente>0123456789</codiceRegionalePaziente> <codiceFiscale/> <nome>nomeBulk01</nome> <cognome>cognomeBulk01</cognome> <dataNascita>1989-12-31</dataNascita> <sesso>F</sesso> <nazionalita>380<

efficient way to transform XML document into tabular dataset in SQL because cross apply xml query performs exponentially worse as xml grows

六眼飞鱼酱① 提交于 2020-05-30 20:57:27
问题 I have a big size XML document (50.000-100,000) that needs to be parsed on Azure SQL that looks like this: <?xml version="1.0" encoding="UTF-8"?> <covid-19 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://covid-19.iss.it/XMLSchema/0.1/"> <pazienti> <paziente> <codiceRegionalePaziente>0123456789</codiceRegionalePaziente> <codiceFiscale/> <nome>nomeBulk01</nome> <cognome>cognomeBulk01</cognome> <dataNascita>1989-12-31</dataNascita> <sesso>F</sesso> <nazionalita>380<

How convert a Byte[] to a data to insert a value in a varbinary(max) column in SQL Server?

拜拜、爱过 提交于 2020-05-29 08:56:14
问题 I have a object with a byte[] property, and I would like to convert this value to the correct value to can insert it into the database using T-SQL. But I don't know how I could convert the byte[] to the correct value for T-SQL for the insert. Thanks. 回答1: Create a Console Application project and try this code // Sample Class public class MyClass { public byte[] data; } // Main static void Main(string[] args) { MyClass cls = new MyClass(); using (SqlConnection cn = new SqlConnection(

How convert a Byte[] to a data to insert a value in a varbinary(max) column in SQL Server?

有些话、适合烂在心里 提交于 2020-05-29 08:56:14
问题 I have a object with a byte[] property, and I would like to convert this value to the correct value to can insert it into the database using T-SQL. But I don't know how I could convert the byte[] to the correct value for T-SQL for the insert. Thanks. 回答1: Create a Console Application project and try this code // Sample Class public class MyClass { public byte[] data; } // Main static void Main(string[] args) { MyClass cls = new MyClass(); using (SqlConnection cn = new SqlConnection(

How convert a Byte[] to a data to insert a value in a varbinary(max) column in SQL Server?

馋奶兔 提交于 2020-05-29 08:56:11
问题 I have a object with a byte[] property, and I would like to convert this value to the correct value to can insert it into the database using T-SQL. But I don't know how I could convert the byte[] to the correct value for T-SQL for the insert. Thanks. 回答1: Create a Console Application project and try this code // Sample Class public class MyClass { public byte[] data; } // Main static void Main(string[] args) { MyClass cls = new MyClass(); using (SqlConnection cn = new SqlConnection(