sql-server

How to format date on MS SQL Server 2008

∥☆過路亽.° 提交于 2021-02-16 05:10:21
问题 I would like to format dates based on a pattern like for example 22/01/2015 or 2016-12-15. In the .NET Framework we have DateTime -> ToString() method which accepts formats as argument or even string.Format, which does the same. Is there any function on MS SQL Server 2008 that formats date based on a argument pattern? 回答1: I had a similar problem in SQL 2012 they have a great function called format which you could pass in a date and the format you require SELECT FORMAT(GETDATE(), 'dd/mm/yyy')

How to format date on MS SQL Server 2008

人走茶凉 提交于 2021-02-16 05:09:00
问题 I would like to format dates based on a pattern like for example 22/01/2015 or 2016-12-15. In the .NET Framework we have DateTime -> ToString() method which accepts formats as argument or even string.Format, which does the same. Is there any function on MS SQL Server 2008 that formats date based on a argument pattern? 回答1: I had a similar problem in SQL 2012 they have a great function called format which you could pass in a date and the format you require SELECT FORMAT(GETDATE(), 'dd/mm/yyy')

SQL variable to hold list of integers

无人久伴 提交于 2021-02-15 08:12:16
问题 I'm trying to debug someone else's SQL reports and have placed the underlying reports query into a query windows of SQL 2012. One of the parameters the report asks for is a list of integers. This is achieved on the report through a multi-select drop down box. The report's underlying query uses this integer list in the where clause e.g. select * from TabA where TabA.ID in (@listOfIDs) I don't want to modify the query I'm debugging but I can't figure out how to create a variable on the SQL

SQL variable to hold list of integers

一个人想着一个人 提交于 2021-02-15 08:03:25
问题 I'm trying to debug someone else's SQL reports and have placed the underlying reports query into a query windows of SQL 2012. One of the parameters the report asks for is a list of integers. This is achieved on the report through a multi-select drop down box. The report's underlying query uses this integer list in the where clause e.g. select * from TabA where TabA.ID in (@listOfIDs) I don't want to modify the query I'm debugging but I can't figure out how to create a variable on the SQL

SQL Server Dynamic pivot for an unknow number of columns

▼魔方 西西 提交于 2021-02-15 07:44:29
问题 The question has been asked before, but in a slightly different scenario (one that doesn't seem to fit to my question) so.. I have data that looks like this Name |Item |Note George|Paperclip |Two boxes George|Stapler |blue one George|Stapler |red one George|Desk lamp |No light bulb Mark |Paperclip |One box 2" Mark |Paperclip |One box 4" Mark |Block Notes|a blue one ..? |..? |..? And I would want to pivot by name, to obtain Name |Paperclip|Stapler|Desk Lamp|Block Notes George| 1| 2| 1| NULL

Verify that specific joins are made everywhere in a query

浪子不回头ぞ 提交于 2021-02-15 07:39:17
问题 I have to go through hundreds of queries in the form of stored procedures and verify that for every join being made that: a specific column join is always made in the join that the join doesn't exist in a hardcoded format to the previous only value of the column (i.e it needs to be like a.requiredJoinColumn = b.requiredJoinColumn and not a.requiredJoinColumn = 'onlyValue' For example if the required column was named 'reqCol' I'd want to find this as a problem: SELECT a.* FROM tableA a JOIN

Local db error. A network-related or instance-specific error occurred while establishing a connection to SQL Server

≡放荡痞女 提交于 2021-02-15 06:12:04
问题 I have web site running Visual Studio 2015 with local db,everything works great. But production server is not working. connection string is "Data Source = (LocalDB)\MSSQLLocalDB; AttachDbFilename =|DataDirectory|\SeedDb.mdf; Integrated Security=True;MultipleActiveResultSets=True;". i tried connection string "Data Source = (LocalDB)\V11.00; AttachDbFilename =|DataDirectory|\SeedDb.mdf; Integrated Security=True;MultipleActiveResultSets=True;". Full error is : Server Error in '/' Application. A

Local db error. A network-related or instance-specific error occurred while establishing a connection to SQL Server

自古美人都是妖i 提交于 2021-02-15 06:11:54
问题 I have web site running Visual Studio 2015 with local db,everything works great. But production server is not working. connection string is "Data Source = (LocalDB)\MSSQLLocalDB; AttachDbFilename =|DataDirectory|\SeedDb.mdf; Integrated Security=True;MultipleActiveResultSets=True;". i tried connection string "Data Source = (LocalDB)\V11.00; AttachDbFilename =|DataDirectory|\SeedDb.mdf; Integrated Security=True;MultipleActiveResultSets=True;". Full error is : Server Error in '/' Application. A

Extract phone number from noised string

落爺英雄遲暮 提交于 2021-02-14 18:35:00
问题 I have a column in a table that contains random data along with phone numbers in different formats. The column may contain Name Phone Email HTML tags Addresses (with numbers) Examples: 1) Call back from +79005346546, Conversation started<br>Phone: +79005346546<br>Called twice Came from google.com<br>IP: 77.106.46.202 the web page address is xxx.com utm_medium: cpc<br>utm_campaign: 32587871<br>utm_content: 5283041 79005346546 2) John Smith 3) xxx@yyy.com 4) John Smith 8 999 888 77 77 How a

SQL Server Query Error -ORDER BY clause is invalid in views

混江龙づ霸主 提交于 2021-02-12 11:40:40
问题 I am running the below code. When I run this code, I get error message: The ORDER BY clause is invalid in views, inline functions, derived tables, subqueries, and common table expressions, unless TOP or FOR XML is also specified. I'm not sure why I am getting this error message. Help is much appreciated. SELECT a.DELINQ_BUCKET_GROUP, a.vv_count FROM ( SELECT DELINQ_BUCKET_GROUP, CASE WHEN DELINQ_BUCKET_GROUP IS NULL THEN SUM(CASE WHEN DELINQ_BUCKET_GROUP IS NULL THEN 1 ELSE 0 END) ELSE COUNT