Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing results to a variable 1

Status
Not open for further replies.

NeilO123

Programmer
Apr 28, 2009
18
US
Help to a begginer

I am trying to pass the results of a SELECT LEN to a variable and then display the results of the variable, but I must have the code wrong as an example:

USE AdventureWorks;
GO
DECLARE @varLen int
SET @varlen = SELECT LEN(FirstName)
SELECT @varLen
FROM Person.Contact
GO
Any help is appreciated since I intent to use the results of @varLen in a string.

Thanks to all in advance
 
markros thanks but, I need to extract the contents off the the column "appName" which contains a variable length string as long as (70 CHAR) and then take the results of the LEN and do a SET to the column "buttonText" for the string that is in the column "appName" less 8 characters, afterwards SET the column "appName" to 'DCR Tool'

I wish it was as simple as what you have describe
 
why you cannot do then

SET ButtonText = substring(AppName,1, LEN(AppName)-8)
 
Ok,markros, I did try it as follows:
CODE
USE RUMS
GO
--App DCR Tool (CHAR 8)-4
DECLARE @varlen int
SELECT @varlen = len(appName) from dbo.tbl_hits
@varLen=(@varLen-8)
UPDATE dbo.tbl_hits
SET ButtonText = substring(AppName,1, LEN(AppName)-8) ,
appName='DCR Tool'
FROM dbo.tbl_hits
WHERE (appName LIKE 'DCR%')
--
Results
Msg 102, Level 15, State 1, Line 4
Incorrect syntax near '@varLen'.
--
What you had describe should work but, first I need to overcome the syntax error??
 
markros, I also try the following code with a different error message:
CODE
USE RUMS
GO
UPDATE dbo.tbl_hits
SET ButtonText = substring(AppName,1, LEN(AppName)-8) ,
appName='DCR Tool'
FROM dbo.tbl_hits
WHERE (appName LIKE 'DCR%')
Results
Msg 207, Level 16, State 1, Line 0
Invalid column name 'ButtonText'.
 
Do you have ButtonText column in the tbl_Hits?

Can you post your table creation script?
 
markros, you are right. I am in your debt, I should have done a double check of the entire code before posting.

Thanks a lot for the lesson not only on what you have show me but also to review the code for what can be the obvious
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top