Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
asyed01
Starting Member
13 Posts |
Posted - 2009-08-21 : 09:54:08
|
| Hello experts,I’m new to SQL Server database and trying to pull some data. I’ve wrote the following query which give me the required results.SELECT SUM(actualvalue_base) AS 'Actual Revenue Base', bot_salesrepidname AS 'Sales Rep', COUNT(accountidname) AS 'Accounts', bot_upgradeFROM dbo.FilteredOpportunityWHERE (bot_upgrade = 'True') AND (actualvalue IS NOT NULL) AND (bot_salesrepidname NOT IN ('Beth McKellar', 'Ellen Lowden'))GROUP BY bot_salesrepidname, bot_upgradeORDER BY 'Sales Rep'However ideally I want to concatenate bot_salesrepidname with bot_upgrade. After trying a few things I’ve realize that there is a data type difference. Due to this reason I’m not able to join these 2 fields. Now I’m wondering can I CAST these 2 fields? Is there any way by concatenate 2 different data types fields? Bot_salesrepidname is nvarchar and bot_upgrade is bit.Thanks a lot in advance. |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-08-21 : 10:01:33
|
| usecast(bot_upgrade as nvarchar(100))MadhivananFailing to plan is Planning to fail |
 |
|
|
asyed01
Starting Member
13 Posts |
Posted - 2009-08-21 : 10:56:07
|
quote: Originally posted by madhivanan usecast(bot_upgrade as nvarchar(100))MadhivananFailing to plan is Planning to fail
|
 |
|
|
asyed01
Starting Member
13 Posts |
Posted - 2009-08-21 : 10:57:18
|
| Madhivanan,you are the best. It worked. Full points to you. Here is how my query looks like now thanks to you.SELECT bot_salesrepidname AS 'Sales Rep', COUNT(accountidname) AS 'Accounts', SUM(actualvalue_base) AS 'Actual Revenue Base', bot_upgrade AS 'Upgrade', bot_salesrepidname + ' has ' + CAST(bot_upgrade AS nvarchar(100)) AS Expr1FROM dbo.FilteredOpportunityWHERE (bot_upgrade = 'True') AND (actualvalue IS NOT NULL) AND (bot_salesrepidname NOT IN ('Beth McKellar', 'Ellen Lowden'))GROUP BY bot_salesrepidname, bot_upgradeORDER BY 'Sales Rep' |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-08-24 : 02:12:32
|
quote: Originally posted by asyed01 Madhivanan,you are the best. It worked. Full points to you. Here is how my query looks like now thanks to you.SELECT bot_salesrepidname AS 'Sales Rep', COUNT(accountidname) AS 'Accounts', SUM(actualvalue_base) AS 'Actual Revenue Base', bot_upgrade AS 'Upgrade', bot_salesrepidname + ' has ' + CAST(bot_upgrade AS nvarchar(100)) AS Expr1FROM dbo.FilteredOpportunityWHERE (bot_upgrade = 'True') AND (actualvalue IS NOT NULL) AND (bot_salesrepidname NOT IN ('Beth McKellar', 'Ellen Lowden'))GROUP BY bot_salesrepidname, bot_upgradeORDER BY 'Sales Rep'
You are welcome MadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|
|
|