sql-server-2005

SQL Server XML Data Type query issue

▼魔方 西西 提交于 2020-01-05 06:40:09
问题 Please see below SQL Server 2005 script Declare @xmlData XML SET @xmlData = '<?xml version="1.0"?> <bookstore xmlns="http://myBooks"> <book genre="autobiography" publicationdate="1981" ISBN="1-861003-11-0"> <title>The Autobiography of Benjamin Franklin</title> <author> <first-name>Benjamin</first-name> <last-name>Franklin</last-name> </author> <price>8.99</price> </book> <book genre="novel" publicationdate="1967" ISBN="0-201-63361-2"> <title>The Confidence Man</title> <author> <first-name

SQL Insert query is executed twice

☆樱花仙子☆ 提交于 2020-01-05 05:26:10
问题 I'm using adapter.InsertCommand to insert some data into a table. The only problem is that it's executed twice, thus giving me double entries in the DB. I've tried following the example in the documentation of adapter.InsertCommand and my own code, but get the same result. This is my code: public class nokernokDAL { SqlConnection connection = new SqlConnection(); SqlDataAdapter adapter = new SqlDataAdapter(); public nokernokDAL() { connection.ConnectionString = EPiServer.Global.EPConfig[

How to output only one max value from this query in SQL?

妖精的绣舞 提交于 2020-01-05 05:10:24
问题 Yesterday Thomas helped me a lot by providing exactly the query I wanted. And now I need a variant of it, and hopes someone can help me out. I want it to output only one row, namely a max value - but it has to build on the algorithm in the following query: WITH Calendar AS (SELECT CAST(@StartDate AS datetime) AS Date UNION ALL SELECT DATEADD(d, 1, Date) AS Expr1 FROM Calendar AS Calendar_1 WHERE (DATEADD(d, 1, Date) < @EndDate)) SELECT C.Date, C2.Country, COALESCE (SUM(R.[Amount of people per

How to output only one max value from this query in SQL?

柔情痞子 提交于 2020-01-05 05:10:04
问题 Yesterday Thomas helped me a lot by providing exactly the query I wanted. And now I need a variant of it, and hopes someone can help me out. I want it to output only one row, namely a max value - but it has to build on the algorithm in the following query: WITH Calendar AS (SELECT CAST(@StartDate AS datetime) AS Date UNION ALL SELECT DATEADD(d, 1, Date) AS Expr1 FROM Calendar AS Calendar_1 WHERE (DATEADD(d, 1, Date) < @EndDate)) SELECT C.Date, C2.Country, COALESCE (SUM(R.[Amount of people per

Extracting part of a string using sql

☆樱花仙子☆ 提交于 2020-01-05 04:23:46
问题 I have a string which is of the form Text I Want to Discard (TEXT I WANT) I only want the part of the string contained in brackets. How do I go about getting this substring? 回答1: How about this: select substring(col, charindex('(', col), len(col)) from yourtable; See SQL Fiddle with Demo Or check for both brackets. This gets the location of the opening bracket ( and then returns the length of the string between the opening and closing bracket: select substring(col, charindex('(', col),

Removing duplication in dynamic ROW_NUMBER() OVER ORDER BY statement

最后都变了- 提交于 2020-01-05 04:05:44
问题 I have the following snippet from a SQL statements ROW_NUMBER() OVER (ORDER BY CASE WHEN @SortBy = 'column1 ASC' THEN cast(column1 AS sql_variant) WHEN @SortBy = 'column2 ASC' THEN cast(column2 AS sql_variant) WHEN @SortBy = 'column3 ASC' THEN cast(column3 AS sql_variant) WHEN @SortBy = 'column4 ASC' THEN cast(column4 AS sql_variant) ELSE NULL END ASC, CASE WHEN @SortBy = 'column1 DESC' THEN cast(column1 AS sql_variant) WHEN @SortBy = 'column2 DESC' THEN cast(column2 AS sql_variant) WHEN

How to show DataColumns in Dataset DataTable

谁说胖子不能爱 提交于 2020-01-05 02:53:26
问题 I have a query that I put into a dataset as a datatable. The query runs great, however in the datatable it does not list anything in the Data Column, there for I cannot report it... Any ideas why this is not working? My Query is below. SELECT * FROM ( SELECT timeclock.dtTimeIn, timeclock.dtTimeOut, employees.sfirstname, RANK() OVER ( ORDER BY dtTimeIn) rk1, --earliest record gets 1 RANK() OVER (ORDER BY dtTimeOut DESC) rk2 --latest record gets 1 FROM TimeClock INNER JOIN Employees ON

mssql 2005 datetime and jdbc

半世苍凉 提交于 2020-01-05 02:29:33
问题 How can I insert datetime in MS SQL 2005 with JDBC? I using stored procedures to insert in DB: ALTER proc [dbo].[sp_insertid_report] @stream_time_gmt as datetime, @stream_time_local as datetime, @start_time_gmt as datetime, @end_time_gmt as datetime, @start_time_local as datetime, @end_time_local as datetime, @note_id as int, @reported_by as varchar(100), @date_reported as datetime, @date_created as datetime, @date_updated as datetime, @stream_id as int, @Fp_file_path as varchar(300), @Fp

How do I configure an Excel file as a Linked Server in SQL Server?

主宰稳场 提交于 2020-01-04 17:52:53
问题 I have opened the Linked Server dialog to create a Linked Server so that I can import my excel file data to a SQL Server 2005 database. Which provider must I use and what other settings do I need to fill in? 回答1: You would set it up using either OLEDB provider or the provider for ODBC drivers and create a connection using the ODBC Administrator tool on the server to the Excel file. Are you planning to read from this Excel file on a regular basis? If not, then setting it up as a Linked Server

How do I configure an Excel file as a Linked Server in SQL Server?

為{幸葍}努か 提交于 2020-01-04 17:51:12
问题 I have opened the Linked Server dialog to create a Linked Server so that I can import my excel file data to a SQL Server 2005 database. Which provider must I use and what other settings do I need to fill in? 回答1: You would set it up using either OLEDB provider or the provider for ODBC drivers and create a connection using the ODBC Administrator tool on the server to the Excel file. Are you planning to read from this Excel file on a regular basis? If not, then setting it up as a Linked Server