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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 how to add characters and find result as integer

Author  Topic 

rajpes
Starting Member

13 Posts

Posted - 2010-02-11 : 09:26:01


declare @var nvarchar(50)
set @var='2+2+2'
i want to displat 6 which is sum of 2+2+2(without splitting the character!)
--actually when we say just run" select 2+2+2 "it shows 6
how do i do this

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-02-11 : 09:27:42
you can do like EXEC('select ' + @var)
but question is why do want to do this?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

rajpes
Starting Member

13 Posts

Posted - 2010-02-11 : 09:36:16
quote:
Originally posted by visakh16

you can do like EXEC('select ' + @var)
but question is why do want to do this?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/





thank you, but still i m having problem
i have a varchar column which has values like '1+1+1' , '5+4+1' e.t.c
i want to create a new column inselect and display the value corresponding to it.
How do i do this
select col1,exec col1 as col2?
Go to Top of Page

rajpes
Starting Member

13 Posts

Posted - 2010-02-11 : 09:52:43
plz reply
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-02-11 : 09:58:20
its not certainly a good idea to do it this way. If you want to do this you need use 2nd method as shown below

http://sqlblogcasts.com/blogs/madhivanan/archive/2007/11/26/select-columns-from-exec-procedure-name-is-this-possible.aspx

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -