sql-server-2008

standardizing differently formatted varchar field to date in sql server

半世苍凉 提交于 2021-02-10 06:14:41
问题 I know similar questions have been asked in the past, but they still haven't given me a proper solution for my case. I have a database table (third party) that has a varchar column for a datetime value. It contains dates in the following formats. 11181980 8 18 1960 10/01/1960 04-12-1953 041371 7/29/44 Empty String NULL When I select this column, I want to bring the date in a standard format (say mm/dd/yyyy ) when available or NULL. I can only think of a function to do this, but I don't want

standardizing differently formatted varchar field to date in sql server

泄露秘密 提交于 2021-02-10 06:11:07
问题 I know similar questions have been asked in the past, but they still haven't given me a proper solution for my case. I have a database table (third party) that has a varchar column for a datetime value. It contains dates in the following formats. 11181980 8 18 1960 10/01/1960 04-12-1953 041371 7/29/44 Empty String NULL When I select this column, I want to bring the date in a standard format (say mm/dd/yyyy ) when available or NULL. I can only think of a function to do this, but I don't want

Break up monthly data into daily

微笑、不失礼 提交于 2021-02-10 05:32:04
问题 I have budget data for a company in the following montly format. SqlFiddle link here. Dept# YearMonth Budget($) -------------------------- 001 201301 100 001 201302 110 001 201303 105 .. ..... ... 002 201301 200 ... ..... ... I am required to break this up into daily records, which would look like this: Dept# Date Budget($) -------------------------- 001 20130101 xxx 001 20130102 xxx 001 20130103 xxx .. ..... ... I need to generate daily records from each record in the source table. I don't

Determining the current security checks being made (SQL Server)

白昼怎懂夜的黑 提交于 2021-02-09 01:57:25
问题 One thing that I've always hated more than just about anything in MS SQL Server is the way that security works. The security context constantly switches if you look at the server funny and it's often very hard (for me anyway) to predict or debug. In dealing with an issue today, I though, "I wish I could just add a line to my code that would display the security context that SQL Server is using when this code runs." Does such a command exist? For example, SELECT security_context() To be a

SQL: Convert an integer into a hex string?

走远了吗. 提交于 2021-02-08 14:01:30
问题 How do you convert an integer into a string of hex? I want to convert the int into a format that I can use as a color on my page for example '#ff0000'. So for example: --This converts my int to hex: CONVERT(VARBINARY(8), Color) Color, And I want to do something like this: '#' + CONVERT(NVARCHAR(10), CONVERT(VARBINARY(8), Color)) Color But converting a varbinary string just converts it to an ascii character rather than returning the actual hex string 回答1: There is a built in function to

Insert 1 million records from SQL Server to BigQuery table, linked via CDATA odbc driver

馋奶兔 提交于 2021-02-08 10:22:51
问题 I need to insert 1 million (and more) records from a SQL Server table to a BigQuery table, that is present in SQL Server as "linked server" via CDATA odbc driver with remoting daemon in it (documentation). Also, source table might have no column with number of row, Id etc. For now, I can insert 1 record per second into BigQuery with this driver, using this query: INSERT INTO [GBQ].[CDataGoogleBigQuery].[GoogleBigQuery].[natality] SELECT * FROM [natality].[dbo].[natality] GO But for such a

Count of weekdays in a given month

我的未来我决定 提交于 2021-02-08 09:57:33
问题 I was facing a problem on how to create a calculated column based on a column which contains dates. For example, I have a column which contains dates starting from July. The DAY needs to be calculated as described in the picture using SQL server. So basically can a column be created based on an existing column containing a lot of dates? I need this to be dynamic. WeekDay Date Day --------------------------- Friday 3-Jan-14 1 Monday 6-Jan-14 2 Tuesday 7-Jan-14 3 Wednesday 8-Jan-14 4 Thursday 9

Count of weekdays in a given month

被刻印的时光 ゝ 提交于 2021-02-08 09:56:53
问题 I was facing a problem on how to create a calculated column based on a column which contains dates. For example, I have a column which contains dates starting from July. The DAY needs to be calculated as described in the picture using SQL server. So basically can a column be created based on an existing column containing a lot of dates? I need this to be dynamic. WeekDay Date Day --------------------------- Friday 3-Jan-14 1 Monday 6-Jan-14 2 Tuesday 7-Jan-14 3 Wednesday 8-Jan-14 4 Thursday 9

Sql query to determine when threshold was reached

a 夏天 提交于 2021-02-08 06:59:52
问题 I have an interesting SQL problem I'd appreciate some suggestions on. I have a table with the columns: DateAdded Score Team Users will enter their own scores however they will not necessarily be in order (some may be back dated if they do not use the system each day). Each member of the team's score is added together, the team which reaches a threshold score first wins. I want a query which will tell me which team reached the threshold first and on what date. 回答1: I think, this is what you

I need to import data from Excel to SQL Server using VBA

你说的曾经没有我的故事 提交于 2021-02-08 05:48:18
问题 I am trying to import data from another Excel workbook on my PC into SQL Server. I tried with this code, but it doesn't work: Sub insertion() Dim conn As ADODB.Connection Dim rs As ADODB.Recordset Dim sConnString As String Dim rsstring As String Dim m, nrows As Integer Dim loRH As Excel.ListObject Workbooks("test-vba.xls").Activate *connection* Set conn = New ADODB.Connection Set rs = New ADODB.Recordset conn.Open sConnString MsgBox "Start" Set loRH = wkb.ListObjects(1) loRH.ListColumns(1)