?
Solved

SQL Query Alias Names

Posted on 2009-04-17
6
Medium Priority
?
284 Views
Last Modified: 2012-05-06
I am runningteh following query below and I ma getting the correct results.

I want to do another task, add "ml" to every MLUserName returened.

example query returns Alan, i want it to return mlAlan

Thansk in advance
SELECT     TOP (100) PERCENT CountyID, ROC AS mlUserName, COUNT(ROCID) AS CountOfROCID
FROM         dbo.query11
GROUP BY CountyID, ROC
ORDER BY mlUserName

Open in new window

0
Comment
Question by:Brogrim
  • 2
  • 2
  • 2
6 Comments
 
LVL 60

Expert Comment

by:chapmandew
ID: 24168337
SELECT     TOP (100) PERCENT CountyID, 'ml' + ROC AS mlUserName, COUNT(ROCID) AS CountOfROCID
FROM         dbo.query11
GROUP BY CountyID, ROC
ORDER BY mlUserName
0
 
LVL 93

Expert Comment

by:Patrick Matthews
ID: 24168344
SELECT     TOP (100) PERCENT CountyID, 'ml' + ROC AS mlUserName, COUNT(ROCID) AS CountOfROCID
FROM         dbo.query11
GROUP BY CountyID, ROC
ORDER BY mlUserName
0
 
LVL 93

Expert Comment

by:Patrick Matthews
ID: 24168348
too slow :)
0
Restore individual SQL databases with ease

Veeam Explorer for Microsoft SQL Server delivers an easy-to-use, wizard-driven interface for restoring your databases from a backup. No expert SQL background required. Web interface provides a complete view of all available SQL databases to simplify the recovery of lost database

 

Author Comment

by:Brogrim
ID: 24168391
To get teh points how to put the results into a table called tblCounty_mlUserName.

Nearly there
0
 
LVL 60

Accepted Solution

by:
chapmandew earned 2000 total points
ID: 24168411
next time, include that as part of your original question.

--if it exists
insert into tblCounty_mlUserName(countryid, username, count)
SELECT     CountyID, 'ml' + ROC AS mlUserName, COUNT(ROCID) AS CountOfROCID
FROM         dbo.query11
GROUP BY CountyID, ROC

--if it doesn't
SELECT     CountyID, 'ml' + ROC AS mlUserName, COUNT(ROCID) AS CountOfROCID
INTO tblCounty_mlUserName
FROM         dbo.query11
GROUP BY CountyID, ROC
0
 

Author Closing Comment

by:Brogrim
ID: 31571478
a bit moody but very helpfull
0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After restoring a Microsoft SQL Server database (.bak) from backup or attaching .mdf file, you may run into "Error '15023' User or role already exists in the current database" when you use the "User Mapping" SQL Management Studio functionality to al…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question