From the monthly archives:

January 2010

SQL Select Statement

January 27, 2010

in SQL Basics

Out of all the statements in SQL (Structured Query Language), the Select statement is by far the most used once.

The select statement is used to retrieve data from tables/view/combination of tables and views in a database. The result thus generated using this statement is used for display to users through GUI, for reporting purpose, for processing the data and etc.

Such a result generated using a Select Statement is called a Result – Set.

The basic Syntax for a Select Statement is (One thing to be noted over he is SQL is not case sensitive)

SELECT Column_List FROM Table_Name

The <Table_Name> gets more prefixes depending on the Environment we have to select the data from, it can be also written as a three part identifies as [Database Name].[Schema Name].[Table Name]

Here is an example making use of the database AdventureWorks which is available from the site http://www.codeplex.com for download.

Use AdventureWorks
Go
SELECT EmployeeID,NationalIDNumber,Title,ManagerID FROM HumanResources.Employee

The above sql select statement selects four columns from the table Emplyee residing in the schema HumanResources.

EmployeeIDNationalIDNumberTitleManagerID
114417807Production Technician - WC6016
2253022876Marketing Assistant6
3509647174Engineering Manager12
4112457891Senior Tool Designer3
5480168528Tool Designer263

Now let us see one more basic example, say instead of a few columns we want to select all the columns in a table, for that we use the asterisk symbol “*”.
When we are going to write it, It’s going to take a form of the below

SELECT * FROM [Database Name].[Schema Name].[Table Name]

Here it is

Use AdventureWorks
Go
SELECT * FROM HumanResources.Employe

That’s it for not, will further write on these basics in the comin articles.
If you have like it and want to get the articles (or) new post at sql like, subscribe to articles through email by entering your email address in the top right and verifying the same.

 if you have any comments, then the below form is for you, go ahead!!!

{ Comments on this entry are closed }

This article is based on an issue that I was facing from a couple of days, although did not figure out an exact solution for the same, but the procedure followed and for the learning’s.

In the SQL Server Reporting Services, I was constantly loosing the database credentials for a Shared Data Sources in a Report Server project in Visual Studio after a doing a check in to the source control and after that do a get latest, this was really annoying.

SSRS No Credentials

The quick fix was to update the credentials on the Report manager front. This way the data is stored all in the ReportServer database that was specified when setting up SQL Server Reporting Services.

But, once that was done, I just dug into why this was happening and the things responsible for this was found to be the file which was missing from the source control.

When you create a data source “.rds” file is created at the back end which is used in Visual Studio, if you open the file up in a text editor, notice that the username and password is not stored in the file. It is actually stored in the .rptproj.user file. And at many a places people don’t like to keep it on the source control.

SSRS Data Source XML

SSRS Data Source XML

So, in this kind of situation we can either go to the report manager and edit the data source credentials there, and another work around is to add the “User; Password=pass” as part of the Connection String, When the .rds is opened up, the Connection String won’t show this portion, but the Credentials tab should contain the right values.

{ Comments on this entry are closed }