Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 12»»

sql procedure Expand / Collapse
Author
Message
Posted Monday, January 14, 2013 3:16 AM


SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Monday, January 14, 2013 5:35 AM
Points: 191, Visits: 170
I want to display a various statements according to the condition through stored procedure like,

id_student=1 got below remark in subject
like

Id_student Id_subject grade
1 1 Good
1 2 Fair
1 3 Poor
1 4 Good
1 5 Fair
1 6 Poor

now i want to display a statements below,
for Good
Your performance is Good in 1,4
for Fair
Your performance is Fair in 2,5
for Poor
Your performance is Fair in 3,6



I am using mysql database please guide me how to show it ??

I need to show in below format
Id_student Statement
1 Your performance is Good in 1,4
1 Your performance is Fair in 2,5
1 Your performance is Fair in 3,6

please help me.







Thanks & Regards,
Pallavi
Post #1406633
Posted Monday, January 14, 2013 3:37 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Tuesday, November 25, 2014 4:10 AM
Points: 5,221, Visits: 5,119
Hi

This is a Microsoft SQL server forum, not a MySQL forum.

While a number of people here may have MySQL experience, you may be best posting this on a dedicated MySQL forum.

But it looks like you want to do string concatination, which in T-SQL you can do by

'Your performance is '+grade

I would do a google search for "MySQL string concat"




Want an answer fast? Try here
How to post data/code for the best help - Jeff Moden
Need a string splitter, try this - Jeff Moden
How to post performance problems - Gail Shaw
CrossTabs-Part1 & Part2 - Jeff Moden
SQL Server Backup, Integrity Check, and Index and Statistics Maintenance - Ola Hallengren
Managing Transaction Logs - Gail Shaw
Troubleshooting SQL Server: A Guide for the Accidental DBA - Jonathan Kehayias and Ted Krueger

Post #1406637
Posted Monday, January 14, 2013 3:46 AM


SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Monday, January 14, 2013 5:35 AM
Points: 191, Visits: 170
Yes i need concatenation here i user group_concat function but ,

select group_concat('your perfomance is good in',trait_name order by trait_name separator ',')

but its showing your perfomance is good in numerical,'your perfomance is good in verbal,'your perfomance is good in cognition.

which i dont want i need such
'your perfomance is good in numerical,verbal,cogntion
and i used
'your perfomance is good in +' grade as u given it shows result 0 result.



Thanks & Regards,
Pallavi
Post #1406640
Posted Monday, January 14, 2013 3:51 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Tuesday, November 25, 2014 4:10 AM
Points: 5,221, Visits: 5,119
As I say, this is a MS SQL forum, not a MySQL forum, I do not know MySQL.

The example I gave was for MS SQL, you will need to find the MySQL alternative or post the question on a MySQL forum.

Group_Concat is not what you want, that will group the rows together and concatenate.




Want an answer fast? Try here
How to post data/code for the best help - Jeff Moden
Need a string splitter, try this - Jeff Moden
How to post performance problems - Gail Shaw
CrossTabs-Part1 & Part2 - Jeff Moden
SQL Server Backup, Integrity Check, and Index and Statistics Maintenance - Ola Hallengren
Managing Transaction Logs - Gail Shaw
Troubleshooting SQL Server: A Guide for the Accidental DBA - Jonathan Kehayias and Ted Krueger

Post #1406643
Posted Monday, January 14, 2013 3:57 AM


SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Monday, January 14, 2013 5:35 AM
Points: 191, Visits: 170
i want to concat row with comma separator and before that need to add one statement which is common ..


Thanks & Regards,
Pallavi
Post #1406647
Posted Monday, January 14, 2013 5:00 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Yesterday @ 1:11 AM
Points: 2,840, Visits: 3,976
pallavi.unde (1/14/2013)
i want to concat row with comma separator and before that need to add one statement which is common ..
post the sample data with expected output


-------Bhuvnesh----------
I work only to learn Sql Server...though my company pays me for getting their stuff done
Post #1406658
Posted Monday, January 14, 2013 7:13 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Yesterday @ 7:21 AM
Points: 7,135, Visits: 12,749
If you download this SQLCLR component...

http://groupconcat.codeplex.com/

...then you can write code like this in SQL Server very similar to what you would expect to be able to write in MySQL. Adding the ability to more easily port MySQL code to SQL Server is part of why I wrote the component.

CREATE TABLE dbo.x
(
Id_student INT,
Id_subject INT,
grade VARCHAR(10)
)
INSERT INTO dbo.x
(Id_student, Id_subject, grade)
VALUES (1, 1, 'Good'),
(1, 2, 'Fair'),
(1, 3, 'Poor'),
(1, 4, 'Good'),
(1, 5, 'Fair'),
(1, 6, 'Poor');

SELECT Id_student,
'Your performance is ' + grade + ' in ' + GroupConcatTest.dbo.group_concat(Id_subject) AS [Statement]
FROM dbo.x
GROUP BY Id_student,
grade;

There is an XML method as well. If you download group_concat check in the demo scripts for many comparable examples of using group_concat and the XML method.


__________________________________________________________________________________________________
There are no special teachers of virtue, because virtue is taught by the whole community. --Plato
Post #1406709
Posted Monday, January 14, 2013 11:58 AM
SSCarpal Tunnel

SSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal Tunnel

Group: General Forum Members
Last Login: Wednesday, November 26, 2014 11:35 AM
Points: 4,482, Visits: 3,938
In SQL Server, you could use the following:

SELECT 'Your performance is ' + CONVERT(Varchar, grade);

I would consult the MySQL documentation under "string concatenation" for details on how it's done in that database.



Tally Tables - Performance Personified
String Splitting with True Performance
Best practices on how to ask questions
Post #1406888
Posted Monday, January 14, 2013 12:01 PM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Yesterday @ 7:21 AM
Points: 7,135, Visits: 12,749
Ed Wagner (1/14/2013)
In SQL Server, you could use the following:

SELECT 'Your performance is ' + CONVERT(Varchar, grade);

I would consult the MySQL documentation under "string concatenation" for details on how it's done in that database.

This problem goes a bit beyond simple string concatenation.

Consider how you would display the list of subjects the student did poorly in, e.g.

Your performance is Poor in 3,6


__________________________________________________________________________________________________
There are no special teachers of virtue, because virtue is taught by the whole community. --Plato
Post #1406892
Posted Monday, January 14, 2013 12:11 PM
SSCarpal Tunnel

SSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal Tunnel

Group: General Forum Members
Last Login: Wednesday, November 26, 2014 11:35 AM
Points: 4,482, Visits: 3,938
The fields can be concatenated together however they're needed. I certainly don't claim to know MySQL at all - I was just offering a SELECT statement that would return what was needed.


Tally Tables - Performance Personified
String Splitting with True Performance
Best practices on how to ask questions
Post #1406896
« Prev Topic | Next Topic »

Add to briefcase 12»»

Permissions Expand / Collapse