What is wrong with this T-Sql statement

Ben Tam 216 Reputation points
2021-09-20T04:37:17.817+00:00

Dear All,

What's wrong with the following select statement?

string M_Surname="";
string M_GivenName="";
string M_MiddleName="";
int M_StudentID=0
string sSql = "SELECT Top 14 StudentID,Surname,GivenName,MiddleName,ChiName,Remarks FROM Student "

  • "Order by Surname,GivenName,MiddleName,StudentID "
  • "Where Pad(Surname,50)+Pad(GivenName,50)+Pad(MiddleName,50)+Cast(StudentID as Char(8))>"
  • M_Surname.PadRight(50, ' ') + M_GivenName.PadRight(50, ' ') + M_MiddleName.PadRight(50, ' ') + M_StudentID.PadLeft(8, ' ');

TIA

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
12,697 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,237 questions
{count} votes

Accepted answer
  1. Olaf Helper 40,741 Reputation points
    2021-09-20T06:38:06.343+00:00

    What's wrong with the following select statement?

    Nearly everthing. The command order ist wrong, right is SELECT FROM WHERE ORDER.
    And PAD isn't a valid Transact SQL function.

    0 comments No comments

0 additional answers

Sort by: Most helpful