May 8, 2014 at 11:16 pm
I'm trying to do something so simple, it's driving me nuts. Especially since I remember doing it before.
I want to create a computed Column in a SQL Server table, and I want every entry in that column to be the letter Y.
Can someone please tell me what formula I need to type in the formula box in the properties pane of the computed column to pull that off?
Thanks,
May 9, 2014 at 12:23 am
usually when you say u need a computed column, u need to know how u want to have a resulting value For example if u have a table 'Order'. you have columns Qty and Rate and u want to have a computed column of TotalValue then the expression will be
TotalValue = Qty * Rate
Below the Schema.
CREATE TABLE [dbo].[Order](
[Item] [nchar](10) NULL,
[Qty] [float] NULL,
[Rate] [float] NULL,
[TotalValue] AS ([Qty]*[Rate])
) ON [PRIMARY]
you need to share your table schema, formula how to calculate the value 'Y'.
if all you need a value 'Y', regardless any formula, you can a column 'Letter' with Chart(1) and set the Default value to 'Y'.
and thats all.
hope it helps
May 9, 2014 at 1:43 am
ALTER TABLE [tablename] ADD [columnname] AS CAST('Y' as char(1))
Far away is close at hand in the images of elsewhere.
Anon.
May 9, 2014 at 7:36 am
scotsditch (5/8/2014)
I'm trying to do something so simple, it's driving me nuts. Especially since I remember doing it before.I want to create a computed Column in a SQL Server table, and I want every entry in that column to be the letter Y.
Can someone please tell me what formula I need to type in the formula box in the properties pane of the computed column to pull that off?
Thanks,
I see that David provided the code to do this. However, what is the point??? If every row is always the same why do you need to store the value at all? Seems totally pointless to me.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
May 9, 2014 at 7:38 am
Sean Lange (5/9/2014)
scotsditch (5/8/2014)
I'm trying to do something so simple, it's driving me nuts. Especially since I remember doing it before.I want to create a computed Column in a SQL Server table, and I want every entry in that column to be the letter Y.
Can someone please tell me what formula I need to type in the formula box in the properties pane of the computed column to pull that off?
Thanks,
I see that David provided the code to do this. However, what is the point??? If every row is always the same why do you need to store the value at all? Seems totally pointless to me.
+1
I was waiting for the op to say they really wanted a new column with a default value !!!!
Far away is close at hand in the images of elsewhere.
Anon.
May 9, 2014 at 8:27 am
David Burrows (5/9/2014)
Sean Lange (5/9/2014)
scotsditch (5/8/2014)
I'm trying to do something so simple, it's driving me nuts. Especially since I remember doing it before.I want to create a computed Column in a SQL Server table, and I want every entry in that column to be the letter Y.
Can someone please tell me what formula I need to type in the formula box in the properties pane of the computed column to pull that off?
Thanks,
I see that David provided the code to do this. However, what is the point??? If every row is always the same why do you need to store the value at all? Seems totally pointless to me.
+1
I was waiting for the op to say they really wanted a new column with a default value !!!!
+2
A view would do the same as the "computed column". A column with a default value would allow you to store and update in the future should the requirement come.
It still begs the question "Why?????".
May 9, 2014 at 8:34 am
It still begs the question "Why?????".
BWAHAA!!!! Was that pun intended??? 😀
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
May 9, 2014 at 8:36 am
Sean Lange (5/9/2014)
It still begs the question "Why?????".
BWAHAA!!!! Was that pun intended??? 😀
🙂
May 9, 2014 at 12:46 pm
Sean Lange (5/9/2014)
scotsditch (5/8/2014)
I'm trying to do something so simple, it's driving me nuts. Especially since I remember doing it before.I want to create a computed Column in a SQL Server table, and I want every entry in that column to be the letter Y.
Can someone please tell me what formula I need to type in the formula box in the properties pane of the computed column to pull that off?
Thanks,
I see that David provided the code to do this. However, what is the point??? If every row is always the same why do you need to store the value at all? Seems totally pointless to me.
The value's not being stored, since it's a computed column (and not involved in an index or something else that requires persisting it).
SQL DBA,SQL Server MVP(07, 08, 09) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".
May 9, 2014 at 12:52 pm
ScottPletcher (5/9/2014)
Sean Lange (5/9/2014)
scotsditch (5/8/2014)
I'm trying to do something so simple, it's driving me nuts. Especially since I remember doing it before.I want to create a computed Column in a SQL Server table, and I want every entry in that column to be the letter Y.
Can someone please tell me what formula I need to type in the formula box in the properties pane of the computed column to pull that off?
Thanks,
I see that David provided the code to do this. However, what is the point??? If every row is always the same why do you need to store the value at all? Seems totally pointless to me.
The value's not being stored, since it's a computed column (and not involved in an index or something else that requires persisting it).
I still don't see the point if the value is always the same thing? There is no actual benefit that I can come up with to bother with such a thing. It is a constant.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
Viewing 10 posts - 1 through 9 (of 9 total)
You must be logged in to reply to this topic. Login to reply