tsql

Select only half the records

ぐ巨炮叔叔 提交于 2021-02-05 02:28:03
问题 I am trying to figure out how to select half the records where an ID is null. I want half because I am going to use that result set to update another ID field. Then I am going to update the rest with another value for that ID field. So essentially I want to update half the records someFieldID with one number and the rest with another number splitting the update basically between two values for someFieldID the field I want to update. 回答1: In oracle you can use the ROWNUM psuedocolumn. I

Select only half the records

廉价感情. 提交于 2021-02-05 02:26:48
问题 I am trying to figure out how to select half the records where an ID is null. I want half because I am going to use that result set to update another ID field. Then I am going to update the rest with another value for that ID field. So essentially I want to update half the records someFieldID with one number and the rest with another number splitting the update basically between two values for someFieldID the field I want to update. 回答1: In oracle you can use the ROWNUM psuedocolumn. I

Select only half the records

吃可爱长大的小学妹 提交于 2021-02-05 02:25:41
问题 I am trying to figure out how to select half the records where an ID is null. I want half because I am going to use that result set to update another ID field. Then I am going to update the rest with another value for that ID field. So essentially I want to update half the records someFieldID with one number and the rest with another number splitting the update basically between two values for someFieldID the field I want to update. 回答1: In oracle you can use the ROWNUM psuedocolumn. I

SQL Contains() not returning results for 'The'

删除回忆录丶 提交于 2021-02-04 21:10:50
问题 I have SQL script as below for querying my ContactInfoes table SELECT * FROM ContactInfoes WHERE CONTAINS(Name, 'The') I am getting only empty result set. I have an entry in my table with Name 'The Company'. Why I am not getting any data here and how this can be resolved. Any help is appreciated. I am using SQL Server 2019 回答1: You have created FULLTEXT index without specifying STOPLIST. Thus, the default STOPLIST was used. By default the word 'the' is the stop word, that removed from your

Split multiple comma separated columns into rows

人走茶凉 提交于 2021-02-04 19:01:59
问题 I have one table (SQL Server), which has comma separated values in multiple columns, like below: Rule_ID ListType_ID Values 1 1,2 100,200 2 3,4 300,400 I want to split the comma separated values and convert them into rows. The required output must be like below: Rule_ID ListType_ID Values 1 1 100 1 2 200 2 3 300 2 4 400 I have tried the below query: DECLARE @TEMP AS TABLE ( [Rule_ID] INT, [ListType_ID] VARCHAR(MAX), [Values] VARCHAR(MAX) ) INSERT INTO @TEMP SELECT 1, '1,2', '100,200' UNION

Split multiple comma separated columns into rows

对着背影说爱祢 提交于 2021-02-04 19:01:07
问题 I have one table (SQL Server), which has comma separated values in multiple columns, like below: Rule_ID ListType_ID Values 1 1,2 100,200 2 3,4 300,400 I want to split the comma separated values and convert them into rows. The required output must be like below: Rule_ID ListType_ID Values 1 1 100 1 2 200 2 3 300 2 4 400 I have tried the below query: DECLARE @TEMP AS TABLE ( [Rule_ID] INT, [ListType_ID] VARCHAR(MAX), [Values] VARCHAR(MAX) ) INSERT INTO @TEMP SELECT 1, '1,2', '100,200' UNION

In SQL Server 2005, is it possible to set transaction isolation level on a per-user basis?

筅森魡賤 提交于 2021-02-04 18:30:47
问题 In SQL Server 2005, is it possible to automatically set transaction isolation level to, say, read uncommitted an a per-user basis? (So for instance, if I set such a login option for user Fred, Fred wouldn't have to remember sprinkle his select statements with NOLOCK hints or remember to add in a set transaction isolation level statement to his sql.) 回答1: if it is for stored procs you could have code like this in the procs if user_name() in('dbo','username','otherusers','bla') set transaction

using “USE” keyword Vs. full table name in T-SQL

我怕爱的太早我们不能终老 提交于 2021-02-04 17:58:06
问题 When I want to select from table Y in database X I can use select * from [X].[dbo].[Y] or USE X select * from [Y] Is there any reason to prefer one over the other? 回答1: dbo Using dbo as the owner of all the database objects can simplify managing the objects. You will always have a dbo user in the database. Users in the database will be able to access any object owned by dbo without specifying the owner as long as the user has appropriate permission. USE X When a SQL Server login connects to

Using a comma-separated parameter in an IN clause

左心房为你撑大大i 提交于 2021-02-04 15:10:42
问题 I have 'param1, param2, parma3' coming from SSRS to a stored procedure as a varchar parameter: I need to use it in a query's IN clause but then need to change its format like this first: select * from table1 where col1 in('param1', 'param2', 'param3') What is the best way to reformat the parameter without creating functions and parameter tables? 回答1: Try this one, Just need to add commas at the beginning and at the end of @params string. Declare @params varchar(100) Set @params = ',param1

select data up to a space?

谁说我不能喝 提交于 2021-02-04 09:57:18
问题 I have an MSSQL database field that looks like the examples below: u129 james u300 chris u300a jim u202 jane u5 brian u5z brian2 Is there a way to select the first set of characters? Basically select all the characters up until the first line space? I tried messing around with LEFT, RIGHT, LEN, but couldn't figure out a way to do it with variable string lengths like in my example. Thanks! 回答1: You can use a combiation of LEFT and CHARINDEX to find the index of the first space, and then grab