Handling Multiple Results in SQL Server 2008 R2 - tsql

I have a stored procedure with input parameters which returns two result sets.
Out of the two result sets, I have to fetch the second one through the query. Could you please help with this?

Related

Data Comparison between SAP Hana and SQL Server

I am working on a solution to compare Datasets from SAP HANA and Azure SQL Server to check consistency of data on SQL server.
Instead of getting all the fields from HANA and doing an "except",
I was thinking of evaluating and comparing a Checksum or Hashbytes on both systems.
However, the Hashvalues for same data is not matching.
Hash Values on SAP HANA
SELECT HASH_MD5(MANDT), HASH_SHA256(MANDT) from SLT_DECO100.MSKU where CHARG = 'UK2031RP' and WERKS = 'U72D'
0x25DAAD3D9E60B45043A70C4AB7D3B1C6
0x47DC540C94CEB704A23875C11273E16BB0B8A87AED84DE911F2133568115F254
Hash Values on SQL Server
select HASHBYTES('MD5', MANDT), HASHBYTES('SHA2_256', MANDT)
from consolidation.MSKU where CHARG = 'UK2031RP' and WERKS = 'U72D'
0xA4DC01E53D7E318EAB12E235758CFDC5
0x04BC92299F034949057D131F2290667DE4F97E016262874BA9703B1A72AE712A
Need support to understand and perform comparison
The hash values could be different based on algorithms what we are using.
Here in the below link comparing the data from two different environments of same tables by providing the pipe delimiters in query.
The pipe delimiters will separates the data from column to column then it gives the accurate results.
Check here for Compare Records Using Hash Values.
Note: More information for the below text in Microsoft Docs,
Algorithms (MD2, MD4, MD5, SHA & SHA1) are deprecated starting with SQL Server 2016 (13.x).
Use SHA2_256 or SHA2_512 instead. Older algorithms will continue working, but they will raise a deprecation event.

Convert Oracle to T-SQL

Сan you help me to convert this Oracle rule to T-SQL.
SELECT CAST(SYS_CONTEXT('CLIENTCONTEXT', 'AccessSubject') AS NVARCHAR2(255)) AS AccessSubjectCode FROM DUAL
I would like to know how this will be in T-SQL : SYS_CONTEXT()
The SYS_CONTEXT('CLIENTCONTEXT', 'AccessSubject') call returns a value configured by the client application. See https://docs.oracle.com/cd/B28359_01/network.111/b28531/app_context.htm#DBSEG98209 for details.
The most similar feature in SQL Server is the CONTEXT_INFO() function. See https://msdn.microsoft.com/en-us/library/ms180125.aspx. However, in SQL Server the context can store just a single value, of maximum 128 bytes (as opposed to Oracle, where there are multiple contexts and you can store multiple named values in each context).

Viewing data types of columns in query result

Is there a way to see the data types of values in a query result in SQL Developer? I've got a query that I'm going to run in Java, and I need to know what the data types of the different columns are so I can read the ResultSet properly (using SQL Developer to debug the queries). I don't want to have to open all of the separate tables individually in order to see the type of the one or two columns I'm retrieving.

how to find record count mismatch in a stored procedure in sql server 2008 R2?

2 stored procedures are developed by .net developers. which are giving same record counts when you pass the same parameter?
now due to some changes , we are getting mismatch record count i.e
if first stored procedure is giving 2 records for a paramemter , the second SP is giving only 1 record.
to find this i followed the approach like
i verified
i counted total records of a table after joining
total tables used in joining
3.distinct / group by is used in 2 tables or not?
finally i am not able to find the issue.
how do i fix it?
could any body share some ideas.
thanks in advance?
Assuming the same JOINs and filters, then the problem is NULLs.
That is, either
A WHERE clause has a direct NULL comparison which will fail
A COUNT is on a nullable column. See Count(*) vs Count(1) for more
Either way, why do you have the same very similar stored procedures written by 2 different developers, that appear to have differences?

Nhibernate Expression.In limit

I am querying the Nhibernate criteria query with more then 2100 values for In clause.
I do something like Session.CreateCriteria(typeof()).Add(Expression.In("fieldName",arrayValue))
Where arrayValue contains more then 2100 values. I face error
Exception occurred:
UnknownError
NHibernate.ADOException: could not execute query ..then the query with more then 3000 values in array.
with some google help we found out that IN clause in Sql supports only till 2100 values.
Does anyone has faced similar issue earlier? We do not want to change the query as it is written in some generic way and not customized one.
This is a limitation of SQL Server. I wouldn't suggest doing this, but if you insist, you could work around it by creating a table-value sql function (see http://www.dzone.com/snippets/function-getting-comma) that splits up a string by commas (or whatever delimiter you want) and returns the values as a table, and then pass in all your ID's as (say) a comma separated list in 1 parameter and use a SQLCriterion in your criteria query.
eg:
criteria.Add(
new SQLCriterion("{alias}.ID IN (SELECT element FROM dbo.GetCSVValues(?))",
new[]{csvListOfIds},
new[]{NHibernateUtil.String}))
You could split the array into multiple batches, query multiple times, and then combine the result.