Advertisement
Guest User

dayalDoc

a guest
Aug 15th, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.22 KB | None | 0 0
  1. select custNo,Name,City from customer where not exists (select * from orders where customer.custNo = orders.custno)
  2.  
  3. select a.city ,count(*) as totalCity from customer a where a.city in ('colombo','kandy')and a.gender ='male' group by a.city
  4.  
  5. FUNCTIONS
  6.  
  7. use customerdata
  8. select left(Ltrim(name),1)+'. '+ ltrim(lname) as Name_with_Initial from customer
  9.  
  10.  
  11. use customerdata
  12. select substring(ltrim(name),1,3) from customer
  13.  
  14. use customerdata
  15. select len(ltrim(name)) from customer
  16.  
  17. use customerdata
  18. select reverse(ltrim(name)) from customer
  19.  
  20. use customerdata
  21. select lower(ltrim(name)) from customer
  22.  
  23. use customerdata
  24. select upper(ltrim(name)) from customer
  25.  
  26.  
  27. Numeric Functions
  28.  
  29. use customerdata
  30. select unitprice, round(unitprice,0)as roundPrice from orderdetails
  31.  
  32. use customerdata
  33. select unitprice, square(unitprice)as roundPrice from orderdetails
  34.  
  35. use customerdata
  36. select unitprice, sqrt(81)as roundPrice from orderdetails
  37.  
  38. use customerdata
  39. select unitprice, rand() from orderdetails
  40.  
  41. DATE FUNCTIONS
  42.  
  43. use customerdata
  44. select Name, dob, year(dob),getdate(), year(getdate()) - year(DOB)as age from customer
  45.  
  46. select Name, dob, year(dob),datename(month,dob),getdate(), year(getdate()) - year(DOB)as age from customer
  47.  
  48.  
  49.  
  50.  
  51.  
  52. public SqlDataReader GetData(string queryString, string connectionString)
  53. {
  54.  
  55. SqlConnection connection = new SqlConnection(connectionString);
  56. connection.Open();
  57. SqlCommand command = new SqlCommand(queryString, connection);
  58. SqlDataReader reader = command.ExecuteReader();
  59. SqlDataReader sqlDataReader = reader;
  60. DataTable dataTable = new DataTable();
  61. dataTable.Columns.Add("Customer Id");
  62. dataTable.Columns.Add("Customer Name");
  63. while (sqlDataReader.Read())
  64. {
  65. DataRow row = dataTable.NewRow();
  66. row["Customer Id"] = sqlDataReader["CustomerId"];
  67. row["Customer Name"] = sqlDataReader["CustomerName"];
  68. dataTable.Rows.Add(row);
  69. }
  70. GridView1.DataSource = dataTable;
  71. GridView1.DataBind();
  72. connection.Close();
  73. return reader;
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement