sql-server-2005

Ordering hierarchy from recursive query results in SQL 2005

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-09 23:49:11
问题 I've got a 'Task' table with the following columns (the TaskOrder is for ordering the children within the scope of the parent, not the entire table): TaskId ParentTaskId TaskName TaskOrder I've got this CTE query to return all the rows: with tasks (TaskId, ParentTaskId, [Name]) as ( select parentTasks.TaskId, parentTasks.ParentTaskId, parentTasks.[Name] from Task parentTasks where ParentTaskId is null union all select childTasks.TaskId, childTasks.ParentTaskId, childTasks.[Name] from Task

[Sql-Server]what data type to use for password salt and hash values and what length?

二次信任 提交于 2020-01-09 19:07:28
问题 I am generating salt and hash values from my passwords by using, string salt = CreateSalt(TxtPassword.Text.Length); string hash = CreatePasswordHash(TxtPassword.Text, salt); private static string CreateSalt(int size) { //Generate a cryptographic random number. RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider(); byte[] buff = new byte[size]; rng.GetBytes(buff); // Return a Base64 string representation of the random number. return Convert.ToBase64String(buff); } private static string

[Sql-Server]what data type to use for password salt and hash values and what length?

拜拜、爱过 提交于 2020-01-09 19:07:16
问题 I am generating salt and hash values from my passwords by using, string salt = CreateSalt(TxtPassword.Text.Length); string hash = CreatePasswordHash(TxtPassword.Text, salt); private static string CreateSalt(int size) { //Generate a cryptographic random number. RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider(); byte[] buff = new byte[size]; rng.GetBytes(buff); // Return a Base64 string representation of the random number. return Convert.ToBase64String(buff); } private static string

Efficient way to string split using CTE

六月ゝ 毕业季﹏ 提交于 2020-01-09 10:25:19
问题 I have a table that looks like ID Layout 1 hello,world,welcome,to,tsql 2 welcome,to,stackoverflow The desired output should be Id Splitdata 1 hello 1 world 1 welcome 1 to 1 tsql 2 welcome 2 to 2 stackoverflow I have done this by the below query Declare @t TABLE( ID INT IDENTITY PRIMARY KEY, Layout VARCHAR(MAX) ) INSERT INTO @t(Layout) SELECT 'hello,world,welcome,to,tsql' union all SELECT 'welcome,to,stackoverflow' --SELECT * FROM @t ;With cte AS( select F1.id ,O.splitdata from ( select *,

Is there a way to select nth column in a SELECT clause from a table/view

▼魔方 西西 提交于 2020-01-09 08:04:05
问题 I've this GIGANTIC view with several hundred columns and I need to select 114th column something like: SELECT "144" FROM MyView; PS: Obviously, I don't know the name of the column. I just copied the results row into an Excel file, searched for a particular value that is in EJ column so I want to select all rows showing only nth column in my view to do my further debugging. Cheers! 回答1: If you are using MS SQL Server you can sp_help ViewName and then scroll to the 144th column in the Column

How to export SQL Server 2005 query to CSV

别等时光非礼了梦想. 提交于 2020-01-09 06:07:15
问题 I want to export some SQL Server 2005 data to CSV format (comma-separated with quotes). I can think of a lot of complicated ways to do it, but I want to do it the right way. I've looked at bcp, but I can't figure out how to put the quotes around the fields (except concatenating them to the field values, which is ugly). I guess I could do it with sqlcmd and -o, but that seems ugly for the same reason. Is there a bcp way to do it? Is there a reasonable sqlcmd way to do it? Is there some great,

How to export SQL Server 2005 query to CSV

ぃ、小莉子 提交于 2020-01-09 06:05:27
问题 I want to export some SQL Server 2005 data to CSV format (comma-separated with quotes). I can think of a lot of complicated ways to do it, but I want to do it the right way. I've looked at bcp, but I can't figure out how to put the quotes around the fields (except concatenating them to the field values, which is ugly). I guess I could do it with sqlcmd and -o, but that seems ugly for the same reason. Is there a bcp way to do it? Is there a reasonable sqlcmd way to do it? Is there some great,

Isoweek in SQL Server 2005

喜欢而已 提交于 2020-01-08 21:38:08
问题 In SQL Server 2008 the isoweek can be found with this: SELECT datepart(iso_week, getdate()) Before SQL Server 2008 there were no built-in function to find isoweek. I have been searching high and low for a good syntax to find a userdefined iso_week for SQL Server 2005. I found quite a few solutions. Didn't like any of the solutions I found, most of them didn't work, and they were way too long. Since the issue is very old, I would expect this issue is depleted and the best solution has been

SQL Server error on update command - “A severe error occurred on the current command”

旧城冷巷雨未停 提交于 2020-01-08 17:37:09
问题 Running the following query in SQL Server Management Studio gives the error below. update table_name set is_active = 0 where id = 3 A severe error occurred on the current command. The results, if any, should be discarded. The logs have been truncated there is an update trigger but this isnt the issue the transaction count is zero (@@trancount) I have tried the same update statement on a couple of other tables in the database and they work fine. DBCC CHECKTABLE('table_name'); gives DBCC

Convert Xml to Table SQL Server

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-08 15:53:43
问题 I wonder how can i read a xml data and transform it to a table in TSQL? For example: <row> <IdInvernadero>8</IdInvernadero> <IdProducto>3</IdProducto> <IdCaracteristica1>8</IdCaracteristica1> <IdCaracteristica2>8</IdCaracteristica2> <Cantidad>25</Cantidad> <Folio>4568457</Folio> </row> <row> <IdInvernadero>3</IdInvernadero> <IdProducto>3</IdProducto> <IdCaracteristica1>1</IdCaracteristica1> <IdCaracteristica2>2</IdCaracteristica2> <Cantidad>72</Cantidad> <Folio>4568457</Folio> </row> To 8 3 8