sql-server-2005

Using table just after creating it: object does not exist

最后都变了- 提交于 2019-12-18 09:08:09
问题 I have a script in T-SQL that goes like this: create table TableName (...) SET IDENTITY INSERT TableName ON And on second line I get error: Cannot find the object "TableName" because it does not exist or you do not have permissions. I execute it from Management Studio 2005. When I put "GO" between these two lines, it's working. But what I would like to acomplish is not to use "GO" because I would like to place this code in my application when it will be finished. So my question is how to make

How to get the corresponding comma-separated text for a string of comma separated codes?

廉价感情. 提交于 2019-12-18 09:04:13
问题 I've a table, there is a column called "locations" which is in type of varchar(max). It carries string of comma-separated code, e.g. '1, 3, 4' . On the other hand, I've a table which map these code to some locations, e.g. 1 -- British 2 -- New Zealand 3 -- Hong Kong 4 -- Taiwan My problem is, I'm making a VIEW which will map and replace the content of the column "locations" to the corresponding comma-separated text, e.g. '1, 3, 4' will be 'British, Hong Kong, Taiwan' This is really urgent for

BULK insert error with UNC path and windows Authentication

坚强是说给别人听的谎言 提交于 2019-12-18 08:56:45
问题 I have two servers, One is application server which has webservice and other server is a DB server,which has SQL server 2005 DB. Webservice is a vb.net app and all the input files will be on app server. When my application calls(through webservice) DB server to execute BULK insert statement with UNC path(of app server) using Windows authentication(Integrated security) then it fails with error - System.Data.SqlClient.SqlException: Cannot bulk load because the file "\Servername\Foldername\file1

The quest for 0x0B

老子叫甜甜 提交于 2019-12-18 08:54:55
问题 I get this error when reading some data from an SQL column then converting it to XML: "System.InvalidOperationException: There is an error in XML document (182, 16). ---> System.Xml.XmlException: ' ', hexadecimal value 0x0B, is an invalid character." Fair enough, maybe the data is malformed. Except, how can I find the culprit row? SELECT * from Mytable where Column like '%' + char(0x0B)+'%' returns empty. (obviously I attempted all %+char , char, char+% combinations, just in case) 回答1:

How does SQL server work out the estimated number of rows?

て烟熏妆下的殇ゞ 提交于 2019-12-18 08:31:43
问题 I'm trying to debug a fairly complex stored procedure that joins across many tabls (10-11). I'm seeing that for a part of the tree the estimated number of rows drasticly differs from the actual number of rows - at its worst SQL server estimates that 1 row will be returned, when in actuality 55,000 rows are returned! I'm trying to work out why this is - all of my statistics are up-to-date, and I've updated statistics with a FULLSCAN on several tables. I'm not using any user defined functions

Easiest way to get a total count and a count of a subset?

荒凉一梦 提交于 2019-12-18 08:30:16
问题 I was trying to do this: SELECT COUNT(*), ( SELECT COUNT(*) FROM attend WHERE (DATEPART(WEEKDAY,start_date) = 2 OR DATEPART(WEEKDAY,start_date) = 6) AND empl_no = 12345 ) FROM attend as a WHERE empl_no = 12345 But this seems a little ugly. Is there a better way to do this? 回答1: You could use a CTE: WITH T1 AS ( SELECT DATEPART(WEEKDAY,start_date) AS weekday FROM attend WHERE empl_no = 12345 ) SELECT (SELECT COUNT(*) FROM T1) AS total, (SELECT COUNT(*) FROM T1 WHERE weekday = 2 OR weekday = 6)

What does FixedLenNullInSource in sp_help mean?

ε祈祈猫儿з 提交于 2019-12-18 08:27:15
问题 Taking a look around FixedLenNullInSource is for compatibility with SQL 2000, but what does it actually mean? 回答1: In SQL Server 2008 the definition of sp_help shows this is hardcoded to return "yes" if the column is nullable and one of varbinary , varchar , binary , char 'FixedLenNullInSource' = CASE WHEN Type_name(system_type_id) NOT IN ( 'varbinary', 'varchar', 'binary', 'char' ) THEN '(n/a)' WHEN is_nullable = 0 THEN @no ELSE @yes END In SQL Server 2000 it is defined differently as

Conditional Operator in SQL Where Clause

僤鯓⒐⒋嵵緔 提交于 2019-12-18 07:52:08
问题 I'm wishing I could do something like the following in SQl Server 2005 (which I know isnt valid) for my where clause. Sometimes @teamID (passed into a stored procedure) will be the value of an existing teamID, otherwise it will always be zero and I want all rows from the Team table. I researched using Case and the operator needs to come before or after the entire statement which prevents me from having a different operator based on the value of @teamid. Any suggestions other than duplicating

Selecting GETDATE() function twice in a select list— same value for both?

萝らか妹 提交于 2019-12-18 07:44:09
问题 I have a SELECT statement that uses GETDATE() for two different column values. I'm wondering if by the nature of things those two separate function calls in the same SELECT will return identical values every time? 回答1: No they aren't guaranteed to return identical values every time. Each individual reference to GetDate() is a runtime constant and will keep its value throughout the query... SELECT GETDATE() FROM large_table will return the same value in all rows regardless of how long the

Inserting and transforming data from SQL table

[亡魂溺海] 提交于 2019-12-18 07:25:11
问题 I have a question which has been bugging me for a couple of days now. I have a table with: Date ID Status_ID Start_Time End_Time Status_Time(seconds) (How ling they were in a certain status, in seconds) I want to put this data in another table, that has the Status_ID grouped up as columns. This table has columns like this: Date ID Lunch (in seconds) Break(in seconds) Vacation, (in seconds) etc. So, Status_ID 2 and 3 might be grouped under vacation, Status_ID 1 lunch, etc. I have thought of