tsql

How to join comma separated column values with another table as rows

房东的猫 提交于 2021-02-07 13:31:40
问题 I am trying to join two tables by first converting a comma separated values from a column "SupplierId" which I am doing successfully. However, the issue comes in when I try joining to another table 'Vendors' with the Supplier names via a foreign key 'DCLink'. This is what I mean: The select statement for the Original Table, SELECT InquiryId, SupplierId FROM Procure_InquiryDetails Gives this result InquiryId SupplierId 1 2,3 2 175 3 170,280 5 7 12 8 5,9 I am able to split the columns from

T-SQL UDF vs full expression run-time

ぃ、小莉子 提交于 2021-02-07 09:33:49
问题 I'm trying to make my query readable by using UDF in SQL SERVER but the run time increasing dramatically when using the function. Following is the function I'm using: create function DL.trim_all(@input varchar(max)) returns varchar(max) as begin set @input=replace(replace(replace(@input,' ',''),')',''),'(','') return @input end Instead of writing: SELECT CASE WHEN replace(replace(replace([FULL_NAME_1],' ',''),')',''),'(','')=replace(replace(replace([FULL_NAME_2],' ',''),')',''),'(','') THEN 1

T-SQL UDF vs full expression run-time

折月煮酒 提交于 2021-02-07 09:32:34
问题 I'm trying to make my query readable by using UDF in SQL SERVER but the run time increasing dramatically when using the function. Following is the function I'm using: create function DL.trim_all(@input varchar(max)) returns varchar(max) as begin set @input=replace(replace(replace(@input,' ',''),')',''),'(','') return @input end Instead of writing: SELECT CASE WHEN replace(replace(replace([FULL_NAME_1],' ',''),')',''),'(','')=replace(replace(replace([FULL_NAME_2],' ',''),')',''),'(','') THEN 1

T-SQL UDF vs full expression run-time

爱⌒轻易说出口 提交于 2021-02-07 09:32:19
问题 I'm trying to make my query readable by using UDF in SQL SERVER but the run time increasing dramatically when using the function. Following is the function I'm using: create function DL.trim_all(@input varchar(max)) returns varchar(max) as begin set @input=replace(replace(replace(@input,' ',''),')',''),'(','') return @input end Instead of writing: SELECT CASE WHEN replace(replace(replace([FULL_NAME_1],' ',''),')',''),'(','')=replace(replace(replace([FULL_NAME_2],' ',''),')',''),'(','') THEN 1

SQL how to cut off string

为君一笑 提交于 2021-02-07 08:25:37
问题 I have a column of strings with a city, state and number in each. SPOKANE, WA 232/107 LAS VEGAS, NV 232/117 PORTLAND, OR 232/128 There are many more than just that, but I am wondering how either I could cut off the numbers in this column and just show the city and state or -even better- cut off the numbers and make city and state a separate column. The column is in the same format all the way down for all the different records. Thanks! 回答1: Without doing all of the work for you... City: A

SQL how to cut off string

北城以北 提交于 2021-02-07 08:24:02
问题 I have a column of strings with a city, state and number in each. SPOKANE, WA 232/107 LAS VEGAS, NV 232/117 PORTLAND, OR 232/128 There are many more than just that, but I am wondering how either I could cut off the numbers in this column and just show the city and state or -even better- cut off the numbers and make city and state a separate column. The column is in the same format all the way down for all the different records. Thanks! 回答1: Without doing all of the work for you... City: A

Combine XML from T-SQL

拥有回忆 提交于 2021-02-07 07:24:10
问题 I have two separate tables TVs and Receivers that I am using the FOR XML PATH commands to build XML off of. My issue is that I want to combine the output of my TV XML Build with my Receiver XML Build to create one XML output. So I would have something like this(Which allows me to keep the TVs and Receivers Tags Separate within the FilterData Root): <FilterData> <TVs> <TV> <Type>LCD</Type> <Brand>Samsung</Brand> </TV> <TV> <Type>LCD</Type> <Brand>Panasonic</Brand> </TV> </TVs> <Receivers>

SQL query for combinations without repetition for top N cases

左心房为你撑大大i 提交于 2021-02-07 04:34:47
问题 I need a query which can be used in (or as) a function and retrieves N combinations of M values from a table. Example: Input: table with values in one column in multiple rows Case 1 N=2 M=4 (Record1 to Record4) Table Record1 Record2 Record3 Record4 Output Record1 Record2 Record3 Record4 Record1,Record2 Record1,Record3 Record1,Record4 Record2,Record3 Record2,Record4 Record3,Record4 Case 2 N=3 M=4 (Record1 to Record4) Table Record1 Record2 Record3 Record4 Output Record1 Record2 Record3 Record4

Using single quote in an Exec statement in SQL

早过忘川 提交于 2021-02-06 15:15:39
问题 I am having issues executing a SQL statement from a stored proc having single quotes. Here is my query from a stored procedure that I am executing. EXEC('UPDATE myTABLE SET myCOLUMN = (SELECT Replace('OSINGLEQUOTEJOHN DOE','SINGLEQUOTE','''')') I am trying to update table "myTABLE" column "myCOLUMN" with a value "O'John Doe" The actual query is like this, i tried to simplify it a bit in the above example EXEC('UPDATE myTABLE SET myCOLUMN = (SELECT Replace('+ @IntegrationGuardian2FullName +',

Using single quote in an Exec statement in SQL

女生的网名这么多〃 提交于 2021-02-06 15:14:31
问题 I am having issues executing a SQL statement from a stored proc having single quotes. Here is my query from a stored procedure that I am executing. EXEC('UPDATE myTABLE SET myCOLUMN = (SELECT Replace('OSINGLEQUOTEJOHN DOE','SINGLEQUOTE','''')') I am trying to update table "myTABLE" column "myCOLUMN" with a value "O'John Doe" The actual query is like this, i tried to simplify it a bit in the above example EXEC('UPDATE myTABLE SET myCOLUMN = (SELECT Replace('+ @IntegrationGuardian2FullName +',