sql-server-2005

How to set the default schema of a database in SQL Server 2005?

懵懂的女人 提交于 2019-12-17 16:32:03
问题 The following line works: SELECT * FROM [myschema].users But this does not: SELECT * FROM users 回答1: A default schema is user-specific: USE yourDatabase; ALTER USER [yourUser] WITH DEFAULT_SCHEMA = myschema; More information about the ALTER TABLE for SQL 2005 might help you as well. As this is user-specific, if you have multiple users, you will need to execute this query (on each database) for each user whose default schema you want to update. It is important to note: The value of DEFAULT

Bulk Insert with filename parameter [duplicate]

为君一笑 提交于 2019-12-17 16:27:22
问题 This question already has answers here : How to cast variables in T-SQL for bulk insert? (6 answers) Closed 6 years ago . I need to load a couple of thousands of data files into SQL Server table. So I write a stored procedure that receives just one parameter - file name. But.. The following doesn't work.. The "compiler" complains on @FileName parameter.. It wants just plain string.. like 'file.txt'. Thanks in advance. Ilan. BULK INSERT TblValues FROM @FileName WITH ( FIELDTERMINATOR =',',

Confused about Itzik Ben-Gan's Logical Query Processing order in his SQL Server 2005 book and SQL Server 2008 book

筅森魡賤 提交于 2019-12-17 16:23:11
问题 In the book Inside Microsoft SQL Server™ 2005 T-SQL Querying , the author Itzik Ben-Gan tell us the order or SQL Server 2005's logical query processing is: (8) SELECT (9) DISTINCT (11) <TOP_specification> <select_list> (1) FROM <left_table> (3) <join_type> JOIN <right_table> (2) ON <join_condition> (4) WHERE <where_condition> (5) GROUP BY <group_by_list> (6) WITH {CUBE | ROLLUP} (7) HAVING <having_condition> (10) ORDER BY <order_by_list> 1. FROM 2. ON 3. OUTER (join) 4. WHERE 5. GROUP BY 6.

How to schedule SSIS package to run as something other than SQL Agent Service Account

蹲街弑〆低调 提交于 2019-12-17 16:07:18
问题 In SQL Server 2005, is it possible to schedule an SSIS package to run something other than the SQL Agent Service Account? I've got an SSIS package that makes a connection to a database and runs a stored procedure. My criteria is that I will not specify usernames/passwords in a package or package configuration, so I want to use integrated authentication. The problem is that by default a step in a job runs as SQL Agent Service Account, and our server group does not want to grant that account

How to get calendar Quarter from a date in TSQL

江枫思渺然 提交于 2019-12-17 16:01:02
问题 I have different dates in a column. For example: 20080102 20070821 I want to convert these dates in Year and calendar quarter. E.g., Year Quarter 2008 2008-Q1 2007 2007-Q3 I can get the first column with: select left(date,4) as year from table How can I produce the second column? 回答1: SELECT DATEPART(QUARTER, @date) This returns the quarter of the @date , assuming @date is a DATETIME . 回答2: SELECT DATENAME(Quarter, CAST(CONVERT(VARCHAR(8), datecolumn) AS DATETIME)) 回答3: Here's how I do it.

INSERT INTO TABLE from comma separated varchar-list

♀尐吖头ヾ 提交于 2019-12-17 15:54:31
问题 Maybe i'm not seeing the wood for the trees but i'm stuck, so here's the question: How can i import/insert a list of comma separated varchar-values into a table? I don't mean something like this: '12345678,87654321,11223344' but this: '12345678','87654321','11223344' I have a Split -Function but it seems to be useless in this case, isn't it? Here is a simple (mock-SQL) example to show what i mean: Create Table #IMEIS( imei varchar(15) ) INTO INTO #IMEIS(imei) SELECT * FROM ('012251000362843',

How do I 'subtract' sql tables?

心已入冬 提交于 2019-12-17 15:54:29
问题 Its not really a subtraction I'm looking for. And I know its not a union or intersection... I have been given a long and complex stored procedure that returns a table of active and inactive documents. I have also been given a similar stored procedure that returns another table that contains only the active documents. How could I get a table of inactive documents using these two store procedures? We are using SQL Server 2005. 回答1: The set operation you are looking for is called MINUS, but in

how to increment integer Columns value by 1 in SQL

孤街醉人 提交于 2019-12-17 15:43:08
问题 My questions is how to increment a column's value by 1. For example, suppose a column ID has values 1,2,3,4, .. Now when I update this table then ID column should increment by 1, Now ID will become 2,3,4,5, .. 回答1: To add one to every value in the table... UPDATE myTable SET ID = ID + 1 To create a new value, one more then the previous highest (usually), use a column with IDENTITY 回答2: If you want to have an unique number for each row automatically generated, this is IDENTITY as per Neil's

How to find sum of multiple columns in a table in SQL Server 2005?

北战南征 提交于 2019-12-17 15:39:29
问题 I have a table Emp which has these rows: Emp_cd | Val1 | Val2 | Val3 | Total -------+-------+-------+-------+------- 1 | 1.23 | 2.23 | 3.43 | 2 | 23.03 | 12.23 | 2.92 | 3 | 7.23 | 9.05 | 13.43 | 4 | 03.21 | 78.23 | 9.43 | I want to find SUM of Val1, Val2, Val3 and which will show in the Total column. 回答1: Easy: SELECT Val1, Val2, Val3, (Val1 + Val2 + Val3) as 'Total' FROM Emp or if you just want one row: SELECT SUM(Val1) as 'Val1', SUM(Val2) as 'Val2', SUM(Val3) as 'Val3', (SUM(Val1) + SUM

How to install SQL Server 2005 Express in Windows 8

倾然丶 夕夏残阳落幕 提交于 2019-12-17 15:35:57
问题 I tried to install SQL Server 2005 Express SP3 x64 on Windows 8 but the installer gives me an error: An installation package for the product Microsoft SQL server native Client cannot be found. Try the installation again using a valid copy of the installation package 'sqlncli_x64.msi' How can I solve the problem? 回答1: I had the same problem. But I also had to perform additional steps. Here is what I did. Perform the following steps (Only 64bit version of SQL Server 2005 Developer Edition