sql-server-2012

Powershell SQL server database connectivity and connection timeout issue

给你一囗甜甜゛ 提交于 2021-02-07 20:52:04
问题 I've a powershell script connecting to SQL server 2012 database running a SQL query and result set into data table to send formatted email to relevant parties. Below is the code snippet where issue is: $CBA = New-Object System.Data.DataSet "CBAData" $sqlConn = New-Object System.Data.SqlClient.SqlConnection("Data Source=DataSource;Initial Catalog=DataCatalog;Integrated Security = False;Connection Timeout=800;User ID = user; Password =pwd;") $adapter = New-Object System.Data.SqlClient

Powershell SQL server database connectivity and connection timeout issue

*爱你&永不变心* 提交于 2021-02-07 20:51:38
问题 I've a powershell script connecting to SQL server 2012 database running a SQL query and result set into data table to send formatted email to relevant parties. Below is the code snippet where issue is: $CBA = New-Object System.Data.DataSet "CBAData" $sqlConn = New-Object System.Data.SqlClient.SqlConnection("Data Source=DataSource;Initial Catalog=DataCatalog;Integrated Security = False;Connection Timeout=800;User ID = user; Password =pwd;") $adapter = New-Object System.Data.SqlClient

Powershell SQL server database connectivity and connection timeout issue

假装没事ソ 提交于 2021-02-07 20:49:24
问题 I've a powershell script connecting to SQL server 2012 database running a SQL query and result set into data table to send formatted email to relevant parties. Below is the code snippet where issue is: $CBA = New-Object System.Data.DataSet "CBAData" $sqlConn = New-Object System.Data.SqlClient.SqlConnection("Data Source=DataSource;Initial Catalog=DataCatalog;Integrated Security = False;Connection Timeout=800;User ID = user; Password =pwd;") $adapter = New-Object System.Data.SqlClient

SQL Server: HTML Decode based on the HTML names in a String input

本小妞迷上赌 提交于 2021-02-07 10:16:36
问题 I am trying to convert the HTML names like & " etc to their equivalent CHAR values using the SQL below. I was testing this in SQL Server 2012. Test 1 (This works fine): GO DECLARE @inputString VARCHAR(MAX)= '&testString&' DECLARE @codePos INT, @codeEncoded VARCHAR(7), @startIndex INT, @resultString varchar(max) SET @resultString = LTRIM(RTRIM(@inputString)) SELECT @startIndex = PATINDEX('%&%', @resultString) WHILE @startIndex > 0 BEGIN SELECT @resultString = REPLACE(@resultString, '&', '&'),

SQL Server: HTML Decode based on the HTML names in a String input

五迷三道 提交于 2021-02-07 10:15:28
问题 I am trying to convert the HTML names like & " etc to their equivalent CHAR values using the SQL below. I was testing this in SQL Server 2012. Test 1 (This works fine): GO DECLARE @inputString VARCHAR(MAX)= '&testString&' DECLARE @codePos INT, @codeEncoded VARCHAR(7), @startIndex INT, @resultString varchar(max) SET @resultString = LTRIM(RTRIM(@inputString)) SELECT @startIndex = PATINDEX('%&%', @resultString) WHILE @startIndex > 0 BEGIN SELECT @resultString = REPLACE(@resultString, '&', '&'),

SQL - Running Total - Year To Date, Previous Year To Date, and Last Rolling 12 Months

旧街凉风 提交于 2021-02-05 12:30:49
问题 Thanks for helping me out with this one! I apologize in advance for the formatting, but I think it is easy to follow. Provided is a sample table of data. I need three separate columns created with query language. The running total must go consider the ID and the date. Running 12 Months - I need sum the value of each ID for rolling 12 months. Current YTD - Sum the value of each ID for the current year of the date of the value. Previous YTD - Sum the value of each ID for the year immediately

SQL - Running Total - Year To Date, Previous Year To Date, and Last Rolling 12 Months

纵饮孤独 提交于 2021-02-05 12:30:31
问题 Thanks for helping me out with this one! I apologize in advance for the formatting, but I think it is easy to follow. Provided is a sample table of data. I need three separate columns created with query language. The running total must go consider the ID and the date. Running 12 Months - I need sum the value of each ID for rolling 12 months. Current YTD - Sum the value of each ID for the current year of the date of the value. Previous YTD - Sum the value of each ID for the year immediately

SQL compare two columns for same value

删除回忆录丶 提交于 2021-02-05 10:25:34
问题 With SQL Server 2012, I have two columns that I would like to compare. Both are on the same table, so no joins are needed. Basically I need to compare two columns, for example scan1 and scan2 and if their value's match, then I need a 1 , else 0 . The results of the match would output to AS Results. 回答1: Something like SELECT .... , CASE WHEN scan1 = scan2 THEN 1 ELSE 0 END AS is_equal FROM table1 should do the job. 回答2: You can go like: SELECT CASE WHEN Scan1 = Scan2 THEN 1 ELSE 0 END AS

What is the meaning of the following SQL Server declaration: datetime2(7)?

一个人想着一个人 提交于 2021-02-04 11:48:23
问题 Inside a SQL Server query, there is: datetime2(7) . I know datetime2 , but I don't understand (7) . Can you explain the meaning of (7) ? 回答1: datetime2 [ (fractional seconds precision) ] It's the fractional seconds precision according to the MSDN documentation. http://msdn.microsoft.com/en-us/library/bb677335.aspx This is the microsoft example of 4: DECLARE @datetime2 datetime2(4) = '12-10-25 12:32:10.1234'; So I would assume that 7 would be: DECLARE @datetime2 datetime2(7) = '12-10-25 12:32

How does implicit conversion work with comparisons (< >) of varchar representations of integers in SQL Server?

廉价感情. 提交于 2021-01-29 07:40:45
问题 I've got a query where I'm comparing values with < and > . The database is old and was poorly designed so unfortunately we have columns that should be INT but instead are VARCHAR . The column is called PayCode and is of type VARCHAR(50) . If I have a WHERE clause like this: WHERE PayCode > 200 then when I look at the execution plan there are warnings about implicit conversion and cardinality estimates. What I don't understand is why the below gets rid of those warnings: WHERE PayCode > '200'