Solved

Correct SQL syntax for an expression

Posted on 2008-06-10
2
242 Views
Last Modified: 2010-04-21
I am having difficulty creating an expression as part of an SQL Select query in MS SQL 2000. The expression should generate a URL. I have already done for variables that do not include a number, but now have difficulty.

The question is in the code snippet as follows.
I want to create the following URL:-

<a href="admin/doc.asp?id=Num">Text</a>      

where Num is from an int field varID, and Text is from an nvarchar field. Both from a table tblxyz.
 

The following attempt does not work:-

 '<a href="admin/doc.asp?id=' + STR(dbo.tblxyz.varID) + '''>' + dbo.tblxyz.varTitle + '</a>' AS DocURL
 

Grateful for correct coding! Thanks

Open in new window

0
Comment
Question by:pcardwell
2 Comments
 
LVL 11

Accepted Solution

by:
CMYScott earned 500 total points
Comment Utility
have you tried something like..

'<a href="admin/doc.asp?id=' + CAST(dbo.tblxyz.varID AS varchar(20)) + '">' + dbo.tblxyz.varTitle + '</a>' AS DocURL
0
 

Author Closing Comment

by:pcardwell
Comment Utility
Just tried it and it works perfectly. Thanks!
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

744 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now