Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
Trevor
Starting Member
6 Posts |
Posted - 2005-08-02 : 15:42:46
|
| I have a unique identifier that looks similar to this {B3AC72B0-A538-4657-A8A3-4A3CA4D55589} . My question is, how can I convert this into a varchar in sql. Right now im casting it to this down below which only return bogus numbers when passed to a stored procedure that reads it as a varchar. Any ideas?cast(DealerID as varchar(100)) |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2005-08-02 : 15:44:44
|
| You are doing it correctly. Post the code that you are having problems with.Tara |
 |
|
|
Trevor
Starting Member
6 Posts |
Posted - 2005-08-02 : 15:47:39
|
| ALTER Proc sp_LOAD_DEALER @Dealer as varchar(100)--sp_LOAD_DEALER Jayasselect DealerName as DealerName, DealerID as DealerID,'<a href="AdminEdit.aspx?scid=' + cast(DealerID as varchar(100)) + '" border=0>Edit</a>' [Edit]From DealersWhere (DealerName LIKE @Dealer + '%')I am using a hyperlink in the code to pass an id which is what is inputted into the next stored procedure.alter proc sp_LOAD_FIELDS @DealerID varchar(100)as--sp_LOAD_FIELDS '{B3AC72B0-A538-4657-A8A3-4A3CA4D55589}'Select *, DealerID from DEALERSwhere DealerID = @DealerID |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2005-08-02 : 15:50:55
|
| Try this:alter proc sp_LOAD_FIELDS @DealerID varchar(100)as--sp_LOAD_FIELDS '{B3AC72B0-A538-4657-A8A3-4A3CA4D55589}'--Select *, DealerID --from DEALERS--where DealerID = @DealerIDPRINT @DealerIDGOEXEC sp_LOAD_FIELDS '{B3AC72B0-A538-4657-A8A3-4A3CA4D55589}'Did the correct DealerID get printed to the screen? If you run this inside Query Analyzer, does it work properly:Select *, DealerID from DEALERSwhere DealerID = '{B3AC72B0-A538-4657-A8A3-4A3CA4D55589}'BTW, you should never prefix stored procedures with sp_. You are receiving a performance hit by doing so as SQL Server automatically checks the master database first for this stored procedure. It will then check your current database when it doesn't find it in master. We use usp_ for this reason. sp_ should be reserved by MS use only.Tara |
 |
|
|
Trevor
Starting Member
6 Posts |
Posted - 2005-08-02 : 16:04:45
|
| I tried both of these and they both work correctly in the SQL query analyzer. Which leads me to believe that the problem is in my Vb code that reads in the ID and then passes it to the second stored procedure. Im my page load event I have LoadFields(Request.QueryString("scid"))which then gets passed to the loadfields proceduremycommand = New SqlCommand("sp_LOAD_FIELDS " & DealerID.ToString, myconn)Ill tinker with this, thanks for all your help! |
 |
|
|
|
|
|