![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Hi I'm fairly novice to SQL Server and am trying to make a computed column in my database I have the following columns in tblJobs : JobID Title City State I'm trying to create a computed column that takes the Title and City and strips out any spaces and replaces them with a dash, then concatenates the other columns with dashes. I also have a numeric ID. So if I have JobID : 22333 Title : Nurse Assistant City : Panama City State : FL and want the resulting string to look like this : Nurse-Assistant- Panama-City-FL-22333 I put the following string into the Formula of the Computed Column Specification: Replace(tblJobs.Title," ", "-") + "-" + Replace(tblJobs.City," ", "-") + "-" + State + "-" + (nvarchar(5), JobID) yet the Management Studio says it can't validate this. Am I on the right track here? Or should I try to do the replace (or typecast) somewhere else? Thanks for any help you can provide. Paul |
#3
| |||
| |||
|
|
You are on the right track. Where it probably goes wrong is at *"+ *(nvarchar(5), JobID)" You forgot the word CONVERT, as in *"+ *CONVERT(nvarchar(5), JobID)" -- Gert-Jan j... (AT) thomassharp (DOT) com wrote: Hi I'm fairly novice to SQL Server and am trying to make a computed column in my database I have the following columns in tblJobs : JobID Title City State I'm trying to create a computed column that takes the Title and City and strips out any spaces and replaces them with a dash, then concatenates the other columns with dashes. *I also have a numeric ID. *So if I have JobID : 22333 Title : Nurse Assistant City : Panama City State : FL and want the resulting string to look like this : Nurse-Assistant- Panama-City-FL-22333 I put the following string into the Formula of the Computed Column Specification: Replace(tblJobs.Title," ", "-") + "-" + Replace(tblJobs.City," ", "-") + "-" + State + "-" + *(nvarchar(5), JobID) yet the Management Studio says it can't validate this. Am I on the right track here? *Or should I try to do the replace (or typecast) somewhere else? Thanks for any help you can provide. Paul |
#4
| |||
| |||
|
|
I put the following string into the Formula of the Computed Column Specification: Replace(tblJobs.Title," ", "-") + "-" + Replace(tblJobs.City," ", "-") + "-" + State + "-" + (nvarchar(5), JobID) |
|
yet the Management Studio says it can't validate this. |
![]() |
| Thread Tools | |
| Display Modes | |
| |