sql-server-2012

Querying the Result set of a Previous Query

試著忘記壹切 提交于 2019-12-31 04:03:44
问题 I have a query for example Query1 = Select Name from table where some Criteria . Now this query returns a result set of course, what I want is to query the result set of this query, for example I only want the unique Names from the above query select Distinct(Name) from Query1 . I should mention that I know I can just use distinct in Query1 but this is just an example my real scenario is somewhat different, what I want to know is whether it's possible to query the result set of a previous

Querying the Result set of a Previous Query

坚强是说给别人听的谎言 提交于 2019-12-31 04:03:07
问题 I have a query for example Query1 = Select Name from table where some Criteria . Now this query returns a result set of course, what I want is to query the result set of this query, for example I only want the unique Names from the above query select Distinct(Name) from Query1 . I should mention that I know I can just use distinct in Query1 but this is just an example my real scenario is somewhat different, what I want to know is whether it's possible to query the result set of a previous

Creating a new table from two existing tables with every combination possibility

那年仲夏 提交于 2019-12-31 00:34:13
问题 I have two temporary tables #a and #b both filled with integer values. Let's say they both contain 10 rows with values 1-10. I want to create a third temporary table #c that contains every possible combination of a and b. So it would have 100 rows total with (1,1), (1,2) ... (10, 10). How would I go about doing this in SQL. The implementation I'm using is SQL Server 2012. 回答1: I think you can just do SELECT * INTO #c FROM #a,#b 回答2: Cross join will get all combinations SELECT a.Col , b.Col

retrieving data from SQL in VB (part 2)

瘦欲@ 提交于 2019-12-30 10:53:02
问题 I am trying to populate a listbox by retrieving data from a database through sql. I have asked this question earlier but i was using a different configuration and the one i'm using now isn't giving any results. retrieving data in VB from SQL That is my old post. I will now provide the code to the newer version of my attempt. Imports System.Data.Sql Imports System.Data.SqlClient Public Class Form1 Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load Dim conn As New

Create SQL Server 2012 database compatible for 2008

孤人 提交于 2019-12-30 10:13:30
问题 Is there a way to create a database with SQL Server 2012 and to be able to pass it to SQL Server 2008? 回答1: I just transferred a database from 2012 to 2008 R2. (this requires both to be online and you to have setup the new database with permission to access it, I did this in an office enviroment where the 2012 database was used to create a C# application but the database it was running on was for 2008, you could do this locally I suppose and then backup the data from 2008 to a .bak file once

SQL Server's ISNUMERIC function

≡放荡痞女 提交于 2019-12-30 08:05:49
问题 I need to checking a column where numeric or not in SQL Server 2012. This my case code. CASE WHEN ISNUMERIC(CUST_TELE) = 1 THEN CUST_TELE ELSE NULL END AS CUSTOMER_CONTACT_NO But when the '78603D99' value is reached, it returns 1 which means SQL Server considered this string as numeric. Why is that? How to avoid this kind of issues? 回答1: Unfortunately, the ISNUMERIC() function in SQL Server has many quirks. It's not exactly buggy, but it rarely does what people expect it to when they first

How to fix Visual Studio's error “This server version is not supported…” for SQL Server 2012

核能气质少年 提交于 2019-12-30 06:00:38
问题 I recently installed Visual Studio 2010 and SQL Server 2012 on a Windows Server 2008 R2 machine - (including all updates/Service Packs). When attempting to work on a SQL Server database from within Visual Studio, VS throws the following error: This server version is not supported. Only servers up to Microsoft SQL Server 2008 are supported I recall getting this same error a while back (on a different computer) when I updated a SQL Server 2008 instance to SQL Server 2008 R2 . The fix, back then

SQL Server 2012 Random string from a list

笑着哭i 提交于 2019-12-30 03:56:07
问题 say I have 3 values, Bill, Steve, Jack. and I want to randomly update a table with those values, eg Update contacts set firstname = ('Bill','Steve','Jack') where city = 'NY' how do I randomize these values? Thanks 回答1: You can do this with the following trick: update c set name=ca.name from contacts c outer apply(select top 1 name from (values('bill'),('steve'),('jack')) n(name) where c.id = c.id order by newid())ca; c.id = c.id is just a dummy predicate that forces sql engine to call

Get total row count while paging

倖福魔咒の 提交于 2019-12-30 02:01:18
问题 I have a search screen where the user has 5 filters to search on. I constructed a dynamic query, based on these filter values, and page 10 results at a time. This is working fine in SQL2012 using OFFSET and FETCH , but I'm using two queries to do this. I want to show the 10 results and display the total number of rows found by the query (let's say 1000). Currently I do this by running the query twice - once for the Total count, then again to page the 10 rows. Is there a more efficient way to

Generate Self-signed certificate with Root CA Signer

最后都变了- 提交于 2019-12-30 00:21:13
问题 Scenario: I am using PowerShell on Windows Server 2012r2 to generate a Root certificate and want to use that to sign a newly created Intermediate and Web certificate in dynamic generated (and destroyed) dev/test environments. The scripts are deployed remotely, and the intent is to keep it pure PowerShell if possible. In Windows 10/2016 this is relatively easy, after generating the Root certificate: $Cert = New-SelfSignedCertificate -Signer $Root -Subject "CN=$Subject" I've generated the Root