sql-server-2005

SQL to get list of dates as well as days before and after without duplicates

假装没事ソ 提交于 2019-12-23 15:53:55
问题 I need to display a list of dates, which I have in a table SELECT mydate AS MyDate, 1 AS DateType FROM myTable WHERE myTable.fkId = @MyFkId; Jan 1, 2010 - 1 Jan 2, 2010 - 1 Jan 10, 2010 - 1 No problem. However, I now need to display the date before and the date after as well with a different DateType. Dec 31, 2009 - 2 Jan 1, 2010 - 1 Jan 2, 2010 - 1 Jan 3, 2010 - 2 Jan 9, 2010 - 2 Jan 10, 2010 - 1 Jan 11, 2010 - 2 I thought I could use a union SELECT MyDate, DateType FROM ( SELECT mydate - 1

FTP Connection string using expression in SSIS

天涯浪子 提交于 2019-12-23 15:33:47
问题 In my SSIS 2005 package, I need to give the FTP Connectionstring via an expression as I need to keep it configurable for the user from the dtsConfig file. At the moment I tried giving the following expression: Connectionstring = @[User::FTPServer] + "." + @[User::FTPUser] + "." + @[User::FTPPass] For this unique syntax, I took pointers from the discussion at http://social.msdn.microsoft.com/Forums/en-US/sqlintegrationservices/thread/3713e9a5-343a-4c5b-ac5d-1508cd5ab8be My FTPServer variable

Java/MSSQL: java.sql.SQLException Invalid object name 'TableName'

末鹿安然 提交于 2019-12-23 15:29:30
问题 I'm trying to move a java application from an old server to a new server. The application runs on Tomcat, uses Microsoft SQL Server as the backend DB, and used a system DSN defined in Data Sources (ODBC) to decide where to connect to. The old server used Windows 2000/SQL server 2000, the new server uses Windows 2003/SQL Server 2005. The ODBC definition is identical between servers, and defines the DB to use. On the new server when a user tries to login the following appears in the stdout.log:

Local variables in sp_send_dbmail?

99封情书 提交于 2019-12-23 15:09:02
问题 I'm working on an SQL stored procedure that is supposed to send an attachment with the results of a query. I am using sp_send_dbmail to send the email. Within the query I'd like to send, I join the to a table variable. When I executed the stored procedure, I got an error message which said that the variable didn't exist. My code: DECLARE @t TABLE ( id INT IDENTITY(1,1), some fields ) DECLARE @query VARCHAR(MAX) SET @query = 'SELECT some values FROM @t t INNER JOIN dbo.Table d ON t.field = d

Complex sorting based on next and previous records in SQL

非 Y 不嫁゛ 提交于 2019-12-23 14:42:43
问题 This is a follow-up question on Sorting based on next and previous records in SQL But now it gets a little more complex, for example: If any letter of 1 matches any letter of 2, I want to change the ordering, so that the letter matches with the following record. If no matches are found the normal ordering by letter should be done. The IDs are potentially not succeeding and the records are not persé in the correct order. [SQLFiddle Demo] [Create script and SQL Fiddle demo] create table Parent

Complex sorting based on next and previous records in SQL

江枫思渺然 提交于 2019-12-23 14:39:34
问题 This is a follow-up question on Sorting based on next and previous records in SQL But now it gets a little more complex, for example: If any letter of 1 matches any letter of 2, I want to change the ordering, so that the letter matches with the following record. If no matches are found the normal ordering by letter should be done. The IDs are potentially not succeeding and the records are not persé in the correct order. [SQLFiddle Demo] [Create script and SQL Fiddle demo] create table Parent

How to convert a DateTime string to a DateTime in SQL Server

社会主义新天地 提交于 2019-12-23 13:21:14
问题 I have a DateTime varchar in this format: 2005-08-08T00:00:00+01:00. Does this format have a name? (it's not ISO8601. Is it RFC3339?) How can I convert it to a DateTime using Transact-Sql? EDIT Here's a summary answer, cobbled together from others input: It is ISO8601 with a time offset from UTC. If it was UTC it would end with a 'Z' instead of '+01:00'. wikipedia You can convert it to local time or to utc as follows: DECLARE @d VARCHAR(25) SET @d = '2007-08-08T00:01:00+01:00' SET @d = '2007

SQL Server BETWEEN

被刻印的时光 ゝ 提交于 2019-12-23 13:01:48
问题 I have a table which has Year, Month and few numeric columns Year Month Total 2011 10 100 2011 11 150 2011 12 100 2012 01 50 2012 02 200 Now, I want to SELECT rows between 2011 Nov and 2012 FEB. Note that I want the to Query to use range. Just as if I had a date column in the table.. 回答1: (Year > @FromYear OR Year = @FromYear AND Month >= @FromMonth) AND (Year < @ToYear OR Year = @ToYear AND Month <= @ToMonth) 回答2: Coming up with a way to use BETWEEN with the table as it is will work, but

Sql Server 2005 Puts square brackets around column name

谁说我不能喝 提交于 2019-12-23 12:49:51
问题 I have recently moved a database from Sql Server 2000 to Sql Server 2005. In the table designer, it insists on putting square brackets around a column named "Content" I don't see Content on the list of reserved words for Sql Server, so I don't understand why it is doing this. Is there a way I can prevent it? 回答1: CONTENT is a keyword when defining an XML column with a schema. See here. Edit: The MSDN link is broken (per Champ's comment), so here is the relevant extract: Creating a typed XML

Recursive query with CTE - SUM of child columns for a given parent

和自甴很熟 提交于 2019-12-23 12:38:24
问题 I have a forum database that stores forum information in a single column. The forum allows for unlimited subforums. Table name - forums | ForumID | ParentForumID | Name | Description | TopicCount | ReplyCount | LastPost | Given a ForumID as a parameter I am trying to SUM the TopicCount and ReplyCount for all child entries. I am also trying to return the latest LastPost , which is specified as DATETIME . I've searched google and this forum and understand I should be using a recursive CTE but