[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Data from  SQL Server table and to Rename a table

Posted on 2002-05-26
10
Medium Priority
?
170 Views
Last Modified: 2010-05-02
Hi

Can any one give me the complete code to rename a table in SQL Server and also to read data from a table in SQL server where there are duplicates  say
RollNo , subject  , Studentmarks ,
001    ,  maths    ,100
001    ,   science, 150
0
Comment
Question by:Richards
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 2
  • 2
10 Comments
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 7036253
1. sp_renameDB 'from', 'to'


2. select *
from YourTable
where RollNo in (
   Select RollNo
   FROM YourTable
   GROUP BY RollNo
   HAVING COUNT(*) > 1)
0
 
LVL 17

Accepted Solution

by:
inthedark earned 400 total points
ID: 7036514
Here is a rename function:

Function RenameTableOK(CN As ADODB.Connection, Oldname As String, NewName As String)

' Renames a SQL Server Table
' Example:
'Dim Ok
'Dim CN As ADODB.Connection
'Set CN = New ADODB.Connection
'CN.ConnectionString = "...."
'CN.Open
'Ok = ADO.ReanameTableOK(CN, "MyOldTableName", "MyNewTanleName")

Dim SQL As String
Dim Ok

SQL = "EXEC sp_rename '" + Oldname + "', '" + NewName + "'"

On Error Resume Next
CN.Execute SQL
If Err.Number <> 0 Then
    RenameTableOK = False
Else
    RenameTableOK = True
End If

End Function
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 7036774
inthedark is right. The SP to rename a table is sp_rename (and not sp_renameDB like I told).
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 17

Expert Comment

by:inthedark
ID: 7036784
emoreau very unlike you to be wrong about anything....
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 7128815
Any progress?
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 7297390
This question appears to be abandoned. A question regarding it will be left in the CleanUp
area; if you have any comment about the question, please leave it here.

Unless there is objection or further activity, one of the moderators will be asked to accept the comment
of <emoreau>.

The link to the Community Support area is:
http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt

DO NOT ACCEPT THIS COMMENT AS AN ANSWER.
0
 
LVL 5

Expert Comment

by:Netminder
ID: 7373220
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 7373385
0
 
LVL 5

Expert Comment

by:Netminder
ID: 7373404
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 7373456
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question