sql-server-2005

Is it possible to query a user-specified column name without resorting to dynamic SQL?

不打扰是莪最后的温柔 提交于 2019-12-22 17:39:20
问题 I am trying to implement an API with the following signature: public static List<string> SearchDatabase( string column, string value); The implementation of the API needs to construct an SQL SELECT query with a WHERE clause that uses a column name specified in the column parameter. The query: string query = string.Format( "SELECT Name, @Column " + "FROM Db1 " + "INNER JOIN Db2 ON Db1.Id = Db2.Id " + "WHERE @Column = @Value"); The SQL command and parameters: SqlCommand selectCmd = new

Best practices for dealing with encrypted data in MSSQL

谁说胖子不能爱 提交于 2019-12-22 17:35:54
问题 I have some data in my user database that I would prefer to be encrypted. Most of the data will need to be decrypted when requested, but there are also passwords that can stay encrypted (in the old days we would use pwdcompare but I believe this is obsolete now). I have followed the steps here, so I have now successfully encrypted my data. What I don't understand is the correct way to open the master key at runtime, in order to encrypt/decrypt data. If I want to use stored procedures to

Hierarchical Database Select / Insert Statement (SQL Server)

只愿长相守 提交于 2019-12-22 16:59:08
问题 I have recently stumbled upon a problem with selecting relationship details from a 1 table and inserting into another table, i hope someone can help. I have a table structure as follows: ID (PK) Name ParentID<br> 1 Myname 0<br> 2 nametwo 1<br> 3 namethree 2 e.g This is the table i need to select from and get all the relationship data. As there could be unlimited number of sub links (is there a function i can create for this to create the loop ?) Then once i have all the data i need to insert

Hierarchical Database Select / Insert Statement (SQL Server)

好久不见. 提交于 2019-12-22 16:56:09
问题 I have recently stumbled upon a problem with selecting relationship details from a 1 table and inserting into another table, i hope someone can help. I have a table structure as follows: ID (PK) Name ParentID<br> 1 Myname 0<br> 2 nametwo 1<br> 3 namethree 2 e.g This is the table i need to select from and get all the relationship data. As there could be unlimited number of sub links (is there a function i can create for this to create the loop ?) Then once i have all the data i need to insert

Setting DefaultDataPath and DefaultLogPath on Deploy in VS2010 Database Project

谁都会走 提交于 2019-12-22 16:29:54
问题 To be true the following query is not originally mine, but I am facing the exact issue in my work. And thus copying the problem statement as it is. I am not able to find any solution. I would really appreciate any suggestions or highlights of the following Problem Set: I do not have any hardcoding in Schema Objects\Database Level Objects\Storage\Files - both in database and log files. The deployment script that gets generated when I click "deploy" from db project has hardcoding in :SETVAR

Duplicate Values in Identity Column

谁说胖子不能爱 提交于 2019-12-22 15:33:13
问题 I've got a table which has a column named id which is of type Identity . But this column contains duplicate values 1..8 and then again 1..10 How in the world is this possible? 回答1: I tested what Giogri says and if you enable the Identity Specification (at least on 2008, probably other versions, too) after the table has rows, the DB will start the numbering at the highest integer value. If you have one row with 100 as the column value, then enable Identity, the next insert will be 101. Even

Converting JDE Julian date to Gregorian

拜拜、爱过 提交于 2019-12-22 14:55:32
问题 I'm trying to convert JDE dates, and have amassed a large quantity of information and figured I'd try to do an SQL conversion function to simplify some tasks. Here's the function I came up with, which I simply call "ToGregorian" CREATE FUNCTION [dbo].[ToGregorian](@julian varchar(6)) RETURNS datetime AS BEGIN DECLARE @datetime datetime SET @datetime = CAST(19+CAST(SUBSTRING(@julian, 1, 1) as int) as varchar(4))+SUBSTRING(@julian, 2,2)+'-01-01' SET @datetime = DATEADD(day, CAST(SUBSTRING(

Alternative to SQL BULK INSERT

∥☆過路亽.° 提交于 2019-12-22 12:53:45
问题 I need to import the data form .csv file into the database table (MS SQL Server 2005). SQL BULK INSERT seems like a good option, but the problem is that my DB server is not on the same box as my WEB server. This question describes the same issue, however i don't have any control over my DB server, and can't share any folders on it. I need a way to import my .csv programatically (C#), any ideas? EDIT: this is a part of a website, where user can populate the table with .csv contents, and this

SQL Server 2005 collation issue

自作多情 提交于 2019-12-22 12:49:11
问题 I have two tables, and they are using different collations. It is not allowed to concatenate columns from tables with different collations, for example the following SQL is not allowed, select table1column1 + table2column2 from ... My question is, how to change the collation of a table without destroying the data of the table? thanks in advance, George 回答1: You can change columns collation on the fly if you need to. E.g. select table1column1 collate database default + table2column2 collate

SQL Server 2005 Weird varchar Behavior

女生的网名这么多〃 提交于 2019-12-22 12:31:41
问题 This SQL Server 2005 T-SQL code: DECLARE @Test1 varchar; SET @Test1 = 'dog'; DECLARE @Test2 varchar(10); SET @Test2 = 'cat'; SELECT @Test1 AS Result1, @Test2 AS Result2; produces: Result1 = d Result2 = cat I would expect either The assignment SET @Test1 = 'dog'; to fail because there isn't enough room in @Test1 Or the SELECT to return 'dog' in the Result1 column. What is up with @Test1 ? Could someone please explain this behavior? 回答1: Let me answer with some quotes from the SQL Server