sql-server-2005

Determine if file is empty (SSIS)

夙愿已清 提交于 2019-12-12 11:55:41
问题 I am trying to develop a package in SSIS 2005 and part of my process is to check if a file on the network is empty or not. If it is not empty, I need to pass a status of successful, otherwise, I need to pass a status of unsuccessful. I think I need a script task, but am not sure how to go about it. Any help is appreciated. 回答1: Yes, a Script task will do the job here. Add a using System.IO statement to the top of the script, then something along the lines of the following in the Main method

Storing video duration time in sql server

戏子无情 提交于 2019-12-12 11:45:19
问题 What's the most appropriate type used to store the duration time information of a video in sql server? 回答1: There are several options, including using the builtin DateTime or Time data type with offset from a particular fixed zero (which will allow you to use the built-in date/time function to get hours, minutes and seconds, etc. If you were on pre-SQL Server 2005, you could combine it with a user-defined data type technique (if your spans are less than 24 hours) to constrain the date part to

Not getting the correct count in SQL

这一生的挚爱 提交于 2019-12-12 11:36:56
问题 I am totally new to SQL . I have a simple select query similar to this: SELECT COUNT(col1) FROM table1 There are some 120 records in the table and shown on the GUI . For some reason, this query always returns a number which is less than the actual count. Can somebody please help me? 回答1: You might have some null values in col1 column. Aggregate functions ignore nulls. try this SELECT COUNT(ISNULL(col1,0)) FROM table1 回答2: Try select count(*) from table1 Edit: To explain further, count(*)

Truncate Table and UPDATE Statistics

倖福魔咒の 提交于 2019-12-12 11:35:00
问题 Do we need to Update table statistics after calling Truncate table or it gets updated automatically? Q: Do we need to call "UPDATE STATISTICS" after truncating a table? 回答1: Stats are not automatically updated until the stats are needed again. aka, the TRUNCATE does not do it. So "No". The original answer was "Yes" because it's not automatic as part of TRUNCATE. It depends how you read the question :-) Remember, statistics are updated automatically when needed by a query (eg number of row

Is it bad to use WITH PERMISSION_SET = UNSAFE for an assembly in SQL 2005?

穿精又带淫゛_ 提交于 2019-12-12 11:27:03
问题 I need to use SQLCLR to make a stored procedure that uses stuff in .NET 3.5. If I don't use PERMISSION_SET = UNSAFE I can't do it, it will just die and give me this error: Deploy error SQL01268: .Net SqlClient Data Provider: Msg 6503, Level 16, State 12, Line 1 Assembly 'system.core, version=3.5.0.0, culture=neutral, publickeytoken=b77a5c561934e089.' was not found in the SQL catalog. An error occurred while the batch was being executed. So I found this article: http://weblogs.asp.net

sqlcmd with output file and screen output

橙三吉。 提交于 2019-12-12 11:13:56
问题 I do some command line batch (.bat) with sqlcmd as this way: sqlcmd -i Scripts\STEP01.sql -o PROCESS.log -S MYSERVER -E -d MYDATABASE and i need an output file (it's works currently) and also the output trought the screen to do something like: @echo off echo The result of the query was: sqlcmd -i Scripts\STEP01.sql -o PROCESS.log -S MYSERVER -E -d MYDATABASE pause CHOICE /C:YN /M "Is the result accord?" IF ERRORLEVEL 2 GOTO ENDWITHERROR IF ERRORLEVEL 1 GOTO STEP2 Note : Yes, the script works

Getting ID of record just inserted?

自古美人都是妖i 提交于 2019-12-12 10:55:25
问题 I am processing items users have selected from a gridview, and performing an email and database insert operation. When the user selects a button, the code below takes information from the gridview, creates a new order in the Order table, and creates new entries in the Transactions table. How can I get the last inserted ID if I use this method of inserting a record? Would you recommend a different approach to this simple problem? protected void btnOrder_Click(object sender, EventArgs e) {

Change the default SqlCommand CommandTimeout with configuration rather than recompile?

不想你离开。 提交于 2019-12-12 10:46:59
问题 I am supporting an ASP.Net 3.5 web application and users are experiencing a timeout error after 30 seconds when trying to run a report. Looking around the web it seems it's easy enough to change the timeout in the code, unfortunately I'm not able to access the code and recompile. Is there anyway to configure the default for either the web app, the worker process, IIS or the whole machine? Here is the stack trace up to the point where it's in System.Data in case I'm missing some other problem:

Optimizing ROW_NUMBER() in SQL Server

穿精又带淫゛_ 提交于 2019-12-12 10:43:08
问题 We have a number of machines which record data into a database at sporadic intervals. For each record, I'd like to obtain the time period between this recording and the previous recording. I can do this using ROW_NUMBER as follows: WITH TempTable AS ( SELECT *, ROW_NUMBER() OVER (PARTITION BY Machine_ID ORDER BY Date_Time) AS Ordering FROM dbo.DataTable ) SELECT [Current].*, Previous.Date_Time AS PreviousDateTime FROM TempTable AS [Current] INNER JOIN TempTable AS Previous ON [Current]

Loop through databases on server, and update data

孤街醉人 提交于 2019-12-12 10:40:16
问题 I have a server with multiple databases. I need to loop through these databases and change a value in one record, in one table, in each database. How can this be done? 回答1: You could use dynamic SQL: declare @query varchar(max) set @query = '' select @query = @query + 'UPDATE ' + name + '.dbo.YourTable set value = 1 where id = 2; ' from master.sys.databases where name <> 'master' exec (@query) 回答2: EXEC sp_MSForEachDB ' Use ?; UPDATE ?.dbo.MyTable SET MyValue=999 ' 回答3: There is an