sql-server-2005

Download SQL SERVER AGENT - Microsoft SQL Server

馋奶兔 提交于 2019-12-22 08:24:03
问题 I have downloaded SQL SERVER MANAGEMENT STUDIO but SQL SERVER AGENT is not found. Should I install it separately? Can anybody tell me the link where SQL SERVER AGENT is available as a Freeware to download it? 回答1: The agent is not visible if you use SQL Server Management Studio Express to connect to an SQL Server. You need to install the client tools that come with the server setup to get SQL Server Management Studio. If you are using SQL Server Express, it has no agent. 回答2: SQL Server Agent

How to bulk insert from CSV when some fields have new line character?

梦想与她 提交于 2019-12-22 08:17:53
问题 I have a CSV dump from another DB that looks like this (id, name, notes): 1001,John Smith,15 Main Street 1002,Jane Smith,"2010 Rockliffe Dr. Pleasantville, IL USA" 1003,Bill Karr,2820 West Ave. The last field may contain carriage returns and commas, in which case it is surrounded by double quotes. And I need to preserve those returns and commas. I use this code to import CSV into my table: BULK INSERT CSVTest FROM 'c:\csvfile.csv' WITH ( FIELDTERMINATOR = ',', ROWTERMINATOR = '\n' ) SQL

Sqlbulkcopy doesn't seem to work for me

核能气质少年 提交于 2019-12-22 07:09:07
问题 I have created a datatable and trying to insert that datatable through SqlBulkCopy but somehow it doesn't seem to work for me.... I got the error, The given value of type DateTime from the data source cannot be converted to type decimal of the specified target column. My Datasource is, DataTable dt = new DataTable(); dt.Columns.Add(new DataColumn("EmpId", typeof(Int64))); dt.Columns.Add(new DataColumn("FromDate", typeof(DateTime))); dt.Columns.Add(new DataColumn("ToDate", typeof(DateTime)));

How to get previous row value

爱⌒轻易说出口 提交于 2019-12-22 07:04:05
问题 How to get a value from previous result row of a SELECT statement If we have a table called cardevent and has rows [ID(int) , Value(Money) ] and we have some rows in it, for example ID --Value 1------70 1------90 2------100 2------150 2------300 3------150 3------200 3-----250 3-----280 so on... How to make one Query that get each row ID,Value and the previous Row Value in which data appear as follow ID --- Value ---Prev_Value 1 ----- 70 ---------- 0 1 ----- 90 ---------- 70 2 ----- 100 -----

Web Application to know database update

和自甴很熟 提交于 2019-12-22 06:30:19
问题 My web application (ASP.NET 4) connects to a database (SQL Server 2005). For every new row inserted in a certain table, I want the web app can do some process (like send an email to me with new data). How do I implement the system? My first though is having web app check the table SN column, and have a variable lastProcessedSN . And keep polling every minute. Is it possible to have DB notify web app when there's a new row being inserted? Please advise, thanks. EDIT: Sending an email is just

Inserting an attribute in multiple XML Nodes using XML.modify() in SQL 2005

别说谁变了你拦得住时间么 提交于 2019-12-22 06:06:14
问题 I have an @XML document created from a single select statement. <root> <node> <node1> <targetNode> </targetNode> </node1> <node1> <targetNode> </targetNode> </node1> <node1> <targetNode> </targetNode> </node1> </node> <node> ...... </node> </root> I want to insert the xsi:nil as an attribute of 'targetNode' for this document. @XML.modify( 'insert attribute xsi:nil {"true"} into (root/node/node1/targetNode) [1]') The above will insert the attribute into the first occurance of the targetNode in

SQL Server 2005 - Setting a column as readonly

一曲冷凌霜 提交于 2019-12-22 05:54:19
问题 I have a "InsertTime" field in a table in a SQL Server 2005 database which is defaulted to "getDate()" when the record is first inserted into the database. I want to ensure that this column is not updated again. Can this column be set to readonly or is there a better way to do this without writing all of the sql for the developers? 回答1: Write a stored procedure to do the Update in this table, and make sure it doesn't touch the InsertTime field. Then set all your users' permissions so they can

Select top one from left outer join

家住魔仙堡 提交于 2019-12-22 05:38:28
问题 Guys, I have a query where basically select the latest browser that our user used. here is our (simplified) table structure HITS_TABLE ---------- USERID BROWSER HITSDATE USER_TABLE ---------- USERID USERNAME and here is how I query the latest browser that our user used SELECT U.*, H.BROWSER FROM USER_TABLE U CROSS APPLY (SELECT TOP 1 BROWSER FROM HITS_TABLE WHERE HITS_TABLE.USERID = U.USERID ORDER BY HITS_TABLE.HITSDATE DESC )as H The HITS_TABLE is just added several days ago. So, that query

SQL Performance-wise, what's better: an IF…ELSE clause, or WHERE LIKE clause?

柔情痞子 提交于 2019-12-22 05:23:38
问题 I have a stored procedure that has a optional parameter, @UserID VARCHAR(50) . The thing is, there are two ways to work with it: Give it a default value of NULL , the have an IF...ELSE clause, that performs two different SELECT queries, one with 'WHERE UserID = @UserID' and without the where. Give it a default value of '%' and then just have the where clause use 'WHERE UserID LIKE @UserID' . In the calling code, the '%' wont be used, so only exact matches will be found. The question is: Which

Using RAISERROR isn't working in SQL Server 2005?

烈酒焚心 提交于 2019-12-22 05:14:18
问题 I have the following code below: BEGIN TRY BEGIN TRANSACTION -- DO SOMETHIING COMMIT TRAN END TRY BEGIN CATCH IF(@@TRANCOUNT > 0) ROLLBACK TRANSACTION RAISERROR(ERROR_MESSAGE(), ERROR_SEVERITY(), ERROR_STATE()) --ERROR: Incorrect syntax near 'ERROR_MESSAGE'. END CATCH However, the RAISERROR statement isn't working. What is wrong in the raise error statement? 回答1: RAISERROR follows the same rules as any other stored procedure call. Parameters passed in must be a constant or a variable. You