Skip to content

Tag: sql

How to describe table in SQL Server 2008?

I want to describe a table in SQL Server 2008 like what we can do with the DESC command in Oracle. I have table [EX].[dbo].[EMP_MAST] which I want to describe, but it does not work. Error shown: The object ‘EMP_MAST’ does not exist in database ‘master’ or is invalid for this operation.…

Select the first instance of a record

I have a table, myTable that has two fields in it ID and patientID. The same patientID can be in the table more than once with a different ID. How can I make sure that I get only ONE instance of every patientID.? EDIT: I know this isn’t perfect design, but I need to get some info out of the

SQL server 2012 SP_HELPTEXT extra lines issue

I am using SQL server 2012, & always use SP_HELPTEXT to get my previously created Stored Procedures, In previous versions of SQL server there were no issues in this process but in 2012, My Stored Procedures come with extra lines, for example this is the procedure that I wrote Now after using SP_HELPTEXT w…

Error in LINQ to SQL: specified cast is not valid

Hi I am trying to learn LINQ, and in LINQ to SQL I have got following exception: This is a sample code from Linq In Action by Manning publications. Whats wrong? Exception details: Answer If my memory serves, the Customers table in Northwind does not have CustomerID as int (I think its NVARCHAR). If you wrote …

finding sum of values found from a query

I have a query which returns two rows of data as count. I want to find sum of the column values. My sql: I have tried using Select Sum(my above query) but I am getting error. I just need some of above values. Answer Can grab both result sets in a single query:

Using group by for attributes which will not be selected

Let’s suppose that I have the following table: The question is: Can I group the selection with attributes which don’t appear in the select clause? For example: I know that in this case the group by clause is useless, but it just an example. Is this correct? Answer It’s implementation depende…