tsql

T-SQL - string concatenation

筅森魡賤 提交于 2021-02-20 18:54:40
问题 Hope someone can help - I am a novice SQL hacker (and very bad at it indeed!) I have two tables on SQL Server 2005 TABLE 1 and TABLE2: TABLE1 COL1 COL2 1 10 2 20 3 30 4 10 4 20 5 20 6 30 7 10 7 20 TABLE2 COL1 COL2 10 A 20 B 30 C COL2 in TABLE2 is a character representation of the numerical data in COL2 TABLE1. I hope this is understandable? I have worked out how to select COL1 and COL2 from TABLE1 and concatenate the results to show this: COL1 COL2Concat 1 10 2 20 3 30 4 10, 20 5 20 6 30 7 10

T-SQL - string concatenation

混江龙づ霸主 提交于 2021-02-20 18:53:50
问题 Hope someone can help - I am a novice SQL hacker (and very bad at it indeed!) I have two tables on SQL Server 2005 TABLE 1 and TABLE2: TABLE1 COL1 COL2 1 10 2 20 3 30 4 10 4 20 5 20 6 30 7 10 7 20 TABLE2 COL1 COL2 10 A 20 B 30 C COL2 in TABLE2 is a character representation of the numerical data in COL2 TABLE1. I hope this is understandable? I have worked out how to select COL1 and COL2 from TABLE1 and concatenate the results to show this: COL1 COL2Concat 1 10 2 20 3 30 4 10, 20 5 20 6 30 7 10

TSQL Dynamic Update of TOP(n) Rows

会有一股神秘感。 提交于 2021-02-20 05:18:49
问题 i have a table with one line per travel second table has values of origin and destination and quantity for each combination i need to run an update that run on the second table that update top N rows on the first table (n comes from the second table) im using this update script inside a cursor in a procedure : ALTER PROCEDURE [dbo].[SP_Travels_History_FromMissing] AS BEGIN SET NOCOUNT ON; DECLARE @C_Day_Type_Code INT = NULL DECLARE @C_PartOfDay_Code INT = NULL DECLARE @C_Station_From INT =

DATEDIFF in Business Working Hours & Days Only

别等时光非礼了梦想. 提交于 2021-02-20 04:55:27
问题 I am trying to write a report and am a little stuck :/ I am trying to show the hours and minutes between two dates however minus the non business working hours. Example a business works weekdays between 08:00 until 17:00 and a call was logged at 16:00 today and closed tomorrow at 16:00 so that would be 24 hours minus the business hours so would work out at 9 hours. I have also created a seperate table which holds all the days of the years except weekends and the start of the business working

Convert decimal <--> binary with T-SQL

梦想的初衷 提交于 2021-02-20 03:51:16
问题 How can I convert binary (base 2 stored as varchar) into decimal (base 10 stored as int or bigint) and the other way around, using T-SQL? Example results: 7 (dec) <--> 111 (bin) 136 (dec) <--> 10001000 (bin) 2123942362 (dec) <--> 1111110100110001100100111011010 (bin) 回答1: This answer can handle bigint Convert to bit(varchar containing 1 and 0) DECLARE @input BIGINT = 9223372036854775807 ;WITH N(N)AS ( SELECT top 63 POWER(cast(2 as bigint), ROW_NUMBER()over(ORDER BY (SELECT 1))-1) FROM (VALUES

Convert decimal <--> binary with T-SQL

时间秒杀一切 提交于 2021-02-20 03:49:30
问题 How can I convert binary (base 2 stored as varchar) into decimal (base 10 stored as int or bigint) and the other way around, using T-SQL? Example results: 7 (dec) <--> 111 (bin) 136 (dec) <--> 10001000 (bin) 2123942362 (dec) <--> 1111110100110001100100111011010 (bin) 回答1: This answer can handle bigint Convert to bit(varchar containing 1 and 0) DECLARE @input BIGINT = 9223372036854775807 ;WITH N(N)AS ( SELECT top 63 POWER(cast(2 as bigint), ROW_NUMBER()over(ORDER BY (SELECT 1))-1) FROM (VALUES

SQL LIKE operator not showing any result when it should

浪尽此生 提交于 2021-02-19 13:03:47
问题 I got a Vehicle table with lots of info but one of the columns being 'Owner' in a MSSQL table But one of the owners i can't select when i use LIKE but can if i use = 'Silkeborg Distributionscenter' is the owner (Yes there is a double space in both the table and the param) So the param is: DECLARE @Owners nvarchar(MAX) = 'Silkeborg Distributionscenter' I tried: SELECT * FROM Vehicle WHERE @Owners = Owner --This gave me all the correct results Then: SELECT * FROM Vehicle WHERE @Owners LIKE

SQL LIKE operator not showing any result when it should

生来就可爱ヽ(ⅴ<●) 提交于 2021-02-19 12:54:34
问题 I got a Vehicle table with lots of info but one of the columns being 'Owner' in a MSSQL table But one of the owners i can't select when i use LIKE but can if i use = 'Silkeborg Distributionscenter' is the owner (Yes there is a double space in both the table and the param) So the param is: DECLARE @Owners nvarchar(MAX) = 'Silkeborg Distributionscenter' I tried: SELECT * FROM Vehicle WHERE @Owners = Owner --This gave me all the correct results Then: SELECT * FROM Vehicle WHERE @Owners LIKE

how to add attribute for all subnodes of the xml in sql

泄露秘密 提交于 2021-02-19 08:39:22
问题 I have a xml like below in a variable @xml <ContentTemplate> <Tab Title="Lesson"> <Section Title="Lesson Opening" /> <Section Title="Lesson/Activity" /> </Tab> <Tab Title="Wrap Up and Assessment"> <Section Title="Lesson Closing" /> <Section Title="Tracking Progress/Daily Assessment" /> </Tab> <Tab Title="Differentiated Instruction"> <Section Title="Strategies - Keyword" /> <Section Title="Strategies – Text" /> <Section Title="Resources" /> <Section Title="Acceleration/Enrichment" /> </Tab>

Transact-SQL Select statement results with bad GUID

冷暖自知 提交于 2021-02-19 08:23:21
问题 We have a table with GUID primary keys. When I search for a specific key, I can use either: SELECT * FROM products WHERE productID='34594289-16B9-4EEF-9A1E-B35066531DE6' SELECT * FROM products WHERE productID LIKE '34594289-16B9-4EEF-9A1E-B35066531DE6' RESULT (for both): product_ID Prd_Model ------------------------------------ -------------------------------------------------- 34594289-16B9-4EEF-9A1E-B35066531DE6 LW-100 (1 row affected) We have a customer who uses our ID but adds more text