|
SELECT ColA, Count(*) <br />
FROM TblA <br />
GROUP BY ColA
Regards
KP
|
|
|
|
|
thx dude!
|
|
|
|
|
This will not actuall give the required results. The original question wanted
india japan china USA singapore
4 2 2 1 1
This will give
india 4
japan 2
china 2
USA 1
singapore 1
You actually need to pivot the data.
This code should show you how to do it
<br />
<br />
create table #b1(cola varchar(20))<br />
<br />
insert into #b1<br />
select 'India'<br />
union all<br />
select 'USA'<br />
union all<br />
select 'India'<br />
union all<br />
select 'UK'<br />
<br />
<br />
<br />
<br />
<br />
DECLARE @SQL nvarchar(4000)<br />
SET @SQL='' <br />
<br />
SELECT @SQL= @SQL +<br />
'SUM(CASE WHEN cola=''' + a.cola + ''' THEN 1 ELSE 0 END) AS [' + a.cola + '],'<br />
FROM (select distinct cola from #b1) as a<br />
<br />
select @SQL = left(@SQL,len(@SQL)-1)<br />
<br />
SET @SQL='SELECT ' + @SQL + ' FROM #b1'<br />
EXEC(@SQL)
Hope this helps
Bob
Ashfield Consultants Ltd
|
|
|
|
|
Hi,
Im having two tables in sql server 2000 with same structure in first table if the current sysdate is equal to first table BDate column value means the first table that current sysdate record should be automatically insert to the second table,How can i acheive this one..any suggestions...
First Table:
---------------
Name BDate Content
-------------------------------
Kanna 12/5/2008 Hapy birthday
Second Table:
--------------
Name BDate Content
-------------------------------
Regards
Kanna
|
|
|
|
|
Create a job to fetch all rows from first table that matches to the current date and copies to second table
Schedule the job to execute daily
Regards
KP
|
|
|
|
|
Thanks for ur reply how should i create job.. im new to this concept..can u give me the example code???
regards
Kanna
|
|
|
|
|
From SQL Enterprise Manager, select your server instance and go to
Management -> SQL Server Agent -> Jobs
right click "New Job"
write your SQL query under "step"
then schedule the job
Regards
KP
|
|
|
|
|
Hi everyone,
Does anyone know of an easy way or trick to switch between System.Data.OracleClient and System.Data.SqlClient (and later MySQL's .NET Connector)? I want to give the user the choice of database to use without writing the same database code twice - once for each type of database.
I appreciate all comments or ideas. Thanks!
|
|
|
|
|
Why not use the OleDB classes, which should work for all of those but will be optimised for none ?
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Christian Graus wrote: OleDB classes
I heard oledb and odbc adds an extra processing to the communication and makes it slow. What do you think ?
|
|
|
|
|
I doubt that, I suspect it just means a standard ODBC connection is used instead of an optimised one. But, if he wants to change DBs, then that seems like a simple way to do it.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Ignorance would be the reason.
Thanks a lot!
|
|
|
|
|
Classes like SQLConnection ,OracleConnection and MySQLConnection (.NET connector) are derived from abstract DbConnection class. All the command classes are derived from DbCommand class. So if your data layer uses these and uses a provider model, changing data store would be easy. Colin has written something here[^] which is worth reading.
|
|
|
|
|
Thanks for that and the link.
|
|
|
|
|
I am using the 2005 Edition and I couldn't find a simple "books online" like in the 200 Edition where it gives you basic syntax and code examples.
So I was wondering, is there a way to download the 2000 books online as a document or a stand alone piece of software that doesn't need me to overwrite anything in 2005?
Thanks
modified on Tuesday, May 6, 2008 5:27 AM
|
|
|
|
|
If you install a named instance of 2000, it won't interfere with 2005.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
|
I need to roll back a stored procedure because just altered, By mistake. I need to change the Stored procedure to older version.
I don't have back up of that SP.
Please let me know what should i do?
D.Willington
|
|
|
|
|
Restore from database backup - you do have one don't you?
Restore from your source control system?
Otherwise you are out of luck, SQL does not do versioning.
Bob
Ashfield Consultants Ltd
|
|
|
|
|
Hi Bob
Thanks for your help.
Regards,
Willington.d
D.Willington
|
|
|
|
|
No problem, but I bet its not what you were hoping for
Bob
Ashfield Consultants Ltd
|
|
|
|
|
There was some discussion in the Lounge yesterday qualifying for DailyWTF indicating a delete statement without a where condition.
People are so stingy to maintain db backups and repent only when disaster strikes.
Vasudevan Deepak Kumar
Personal Homepage Tech Gossips
A pessimist sees only the dark side of the clouds, and mopes; a philosopher sees both sides, and shrugs; an optimist doesn't see the clouds at all - he's walking on them. --Leonard Louis Levinson
|
|
|
|
|
Hi all,
i have one doubt , i want to export stored procedures data from sqlserver2000 to ms access, give me any idea .
thanks & regards
sarp
sarp
|
|
|
|
|
You will probably need to rewrite them as Access does not use the same syntax as SQL Server in many instances.
You can export stored procs from enterprise manager by scripting them as create, but I doubt it will help.
Bob
Ashfield Consultants Ltd
|
|
|
|
|
The SQL to Access transition would relatively require a manual intervention at least with respect to Stored Procedures.
Vasudevan Deepak Kumar
Personal Homepage Tech Gossips
A pessimist sees only the dark side of the clouds, and mopes; a philosopher sees both sides, and shrugs; an optimist doesn't see the clouds at all - he's walking on them. --Leonard Louis Levinson
|
|
|
|