Computed Column + Full-Text = Fail

May 30, 2008

I'm trying to figure to figure out the best way to query our database for

One of our developers is implementing a "global search" feature on our intranet. The idea is that a single search string will query multiple columns in a table. For example, searching for "mike fedex" would return the following records:

company | firstname | lastname | notes
FedEx | Mike | Smith | this guy is cool
Paint World | Mike | Anderson | Used to work for FedEx

but not:
Bodum | Mike | Easton | I like apples

because it does not contain all of the search terms.

I tried to create a computed column on our "contacts" table that simply concatenated all of the fields I wanted to search. The idea was to then use CONTAINS or CONTAINSTABLE on the computed column like this: SELECT... WHERE CONTAINS(computed_column, 'word1 AND word1 AND word3'). That would work great, until I realized you can't add a computed column to your full-text index.

Pain.

Any suggestions?

EDIT: The magic sauce needs to be able to search multiple terms across multiple columns with no concern for the order of the words in the search term. For example, searching for "Please Help" and "Help Please" would return the same results. Using LIKE '%Please%Help' and LIKE '%Help%Please' would return very different results.

View 4 Replies


ADVERTISEMENT

Full-text Of XML Data Column

Mar 23, 2004

Hi gurus

A developer created a stored procedure that search in a huge table in a column with ‘like’ statement.
I know that the best solution in most case is use of full-text.

But the content of this specific column is a XML data and Full-text don´t find words as desired.

For example:
Table content:
ID = 1
DsColumn = ´<Name>BETH</Name>´

select * from tbResp
where DsColumn like '%BETH %'
Results:
IDDsColumn
--- ---------------------------------
1<Name>BETH</Name>
1 row(s) affected


select * from tbResp
where
contains(DsColumn, ' BETH ')

0 row(s) affected

Can anyone give me a better solution?

tks

View 1 Replies View Related

Specify Column List In Full Text CONTAINS Search

Apr 18, 2006

Can anybody provide an example of how to specify a column list in a CONTAINS statement? Documentation says it must be comma separated inside parenthesis - I have tried (every combination of) this but always get the error "Incorrect syntax near '('.", for example:

SELECT .... WHERE CONTAINS((Name,Description), '"options"')

This works fine when just querying one column (without the parenthesis).

View 4 Replies View Related

Computed Column Referencing A Computed Column

Sep 5, 2007

Hi all,

I have a table with 3 computed columns, the first two reference a function for there value. The last computed column should be total of the other computed columns, however when trying to write the formula for this column SQL Server rejects it.

Am i correct in thinking it is not possible to reference other computed columns in a computed column's forumla.

My current work around is to call the functions again that the other computed columns use to generate the total, though this seems to me like a performance issue.

Could anyone offer some advise on my situation.

Any input apreciated.

View 1 Replies View Related

Full-text Indexing Of An Image Column With A .PDF File

Mar 16, 2005

Hi,

I am having difficulty in indexing a Table when it contains a PDF file in an Image column. Basically I have a table with a unique id, some other fields, and an Image column. The Image column contains uploaded files from a web application. Full-text indexing works fine for all types of files that I have uploaded into this table which includes (.doc, .xls, .ppt) but I get the following message in my Event Viewer if one of thee files is a PDF file.

One or more documents stored in the Image columns with extension '.pdf' did not get full-text indexed because loading the filter failed with error '1x01'.

I have searched Microsoft's site and implemented their prescribed fixes but none has worked including installation of SP3 of Sql Server and/or modifying the registry key to run the Sql server indexing procedure as a single threaded process.

Has anyone experienced this problem? Please help.

Thanks
Kamal

View 1 Replies View Related

Full-Text On HTML Stored In Nvarchar(MAX) Column

May 2, 2007

What is the best way of using the Full-Text feature on HTML?
I want to only search the text and omit the html tags.

If that involves storing as a different format, can someone tell me the best way of doing that?
I'm very new to sql and especially full-text.

Thanks.

View 1 Replies View Related

Full Text Search And CONTAINSTABLE - Can I Weight By Column?

Aug 8, 2006

I'm trying to use CONTAINSTABLE to do a product search on a number of columns. I want matches on some columns to be weighted higher than for other columns.

It seems like there should be a way to do this with CONTAINSTABLE - I know I can search by multiple strings and weight those matches variably, but what I want is to vary the weight by which column a single term matched. What I have now is a series of UNION queries, which are quite slow:
===================
SELECT m.TitleCode, m.ShortName, m.ShortDescription, a.Rank, 50 as theWeight
FROM CONTAINSTABLE (Product, ShortName, @theSearchTerm) as a, Product m(NoLock)
WHERE a.[KEY] = m.TitleCode

UNION ALL

SELECT m.TitleCode, m.ShortName, m.ShortDescription, a.Rank, 40 as theWeight
FROM FREETEXTTABLE (Product, ShortName, @theSearchTerm) as a, Product m(NoLock)
WHERE a.[KEY] = m.TitleCode

UNION ALL

SELECT m.TitleCode, m.ShortName, m.ShortDescription, a.Rank, 30 as theWeight
FROM FREETEXTTABLE (Product, MatchKeywords, @theSearchTerm) as a, Product m(NoLock)
WHERE a.[KEY] = m.TitleCode

UNION ALL

SELECT m.TitleCode, m.ShortName, m.ShortDescription, a.Rank, 20 as theWeight
FROM FREETEXTTABLE (Product, ShortDescription, @theSearchTerm) as a, Product m(NoLock)
WHERE a.[KEY] = m.TitleCode

ORDER BY 'theWeight' DESC, m.ShortName

===================

What is the better way?

View 1 Replies View Related

No Results Returned For Full Text Search On Varbinary(max) Column

Jul 10, 2007

Hi, I was wondering if any SQL Server gurus out there could help me...I
have a table which contains text resources for my application. The text
resources are multi-lingual so I've read that if I add a html language
indicator meta tag e.g.<META NAME="MS.LOCALE" CONTENT="ES">and
store the text in a varbinary column with a supporting Document Type
column containing ".html" of varchar(5) then the full text index
service should be intelligent about the language word breakers it
applies when indexing the text. (I hope this is correct technique for
best multi-lingual support in a single table?)However, when I come to query this data the results always return 0 rows (no errors are encountered). e.g.DECLARE @SearchWord nvarchar(256)SET @SearchWord = 'search' -- Yes, this word is definitely present in my resources.SELECT * FROM Resource WHERE CONTAINS(Document, @SearchWord)I'm a little puzzled as Full Text search is working fine on another table that employs an nvarchar column.Any pointers / suggestions would be greatly appreciated. Cheers,Gavin.

View 1 Replies View Related

No Results Returned For Full Text Search On Varbinary(max) Column

Jul 10, 2007

Hi, I was wondering if any SQL Server gurus out there could help me...

I have a table which contains text resources for my application. The text resources are multi-lingual so I've read that if I add a html language indicator meta tag e.g.
<META NAME="MS.LOCALE" CONTENT="ES">
and store the text in a varbinary column with a supporting Document Type column containing ".html" of varchar(5) then the full text index service should be intelligent about the language word breakers it applies when indexing the text. (I hope this is correct technique for best multi-lingual support in a single table?)

However, when I come to query this data the results always return 0 rows (no errors are encountered). e.g.
DECLARE @SearchWord nvarchar(256)
SET @SearchWord = 'search' -- Yes, this word is definitely present in my resources.
SELECT * FROM Resource WHERE CONTAINS(Document, @SearchWord)

I'm a little puzzled as Full Text search is working fine on another table that employs an nvarchar column.

Any pointers / suggestions would be greatly appreciated. Cheers,
Gavin.

View 1 Replies View Related

SQL 2005 Bug? Cannot Create Full Text Index For VARBINARY Column That's Populated With Converted NVARCHAR Values

Jul 11, 2007

Hi, I was wondering if any SQL Server gurus out there could help me...I have a table I'm trying to apply a full text catalog to, however no results are ever returned due to the text column being cataloged being of varbinary(max) that's being populated from a converted nvarchar(max) value - I've narrowed it down to this specifically, populating with non nvarchar text seems to work fine.To re-create the problem quickly...If I populate the column viaCONVERT(varbinary(max), 'test text')then there is no problem, I get results as expected.However if I populate the column viaCONVERT(varbinary(max), CAST('test text' as nvarchar(max)))no results are ever returned.Is this a bug with SQL Server 2005 Full Text Indexing? I'm happily creating full text catalogs when an nvarchar is not getting converted into a varbinary.I'm setting the Document Type column to '.html' (I've tried changing this to '.txt' in case it was a fault with the html ifilter but the problem persists so I believe I can rule this out).The reason I need to convert an nvarchar to varbinary is that the table holds multi-lingual text and I'm adding a html meta tag <META NAME="MS.LOCALE" CONTENT="ES"> to the beginning in order for the full text indexing word breaker to select the correct language to catalog the text with. The aim being to provide more relevant searches in users native languages (I've read a few articles that describe this technique, but it's the first time I've tried to apply it).Any pointers / suggestions would be greatly appreciated. Cheers,Gavin.

View 14 Replies View Related

SQL 2005 Bug? Cannot Create Full Text Index For Varbinary Column That's Populated From Converted Nvarchar Values

Jul 11, 2007

Hi, I was wondering if any SQL Server gurus out there could help me...

I have a table I'm trying to apply a full text catalog to, however no results are ever returned due to the text column being cataloged being of varbinary(max) that's being populated from a converted nvarchar(max) value.

To re-create the problem quickly...

If I populate the column via
CONVERT(varbinary(max), 'test text')
then there is no problem, I get results as expected.

However if I populate the column via
CONVERT(varbinary(max), CAST('test text' as nvarchar(max)))
no results are ever returned.

Is this a bug with SQL Server 2005 Full Text Indexing? I'm happily creating full text catalogs when an nvarchar is not getting converted into a varbinary.

I'm setting the Document Type column to '.html' (I've tried changing this to '.txt' in case it was a fault with the html ifilter but the problem persists so I believe I can rule this out).

The reason I need to convert an nvarchar to varbinary is that the table holds multi-lingual text and I'm adding a html meta tag <META NAME="MS.LOCALE" CONTENT="ES"> to the beginning in order for the full text indexing word breaker to select the correct language to catalog the text with. The aim being to provide more relevant searches in users native languages (I've read a few articles that describe this technique, but it's the first time I've tried to apply it).

Any pointers / suggestions would be greatly appreciated. Cheers,
Gavin.

UPDATE: Below is a T-SQL script you can run to demonstrate the effect I'm experiencing...




Code Snippet

-- Create test database
CREATE DATABASE FullTextTest
GO
USE FullTextTest
GO

-- Create test data table
CREATE TABLE TestTable
(
pk UNIQUEIDENTIFIER NOT NULL CONSTRAINT tablePK PRIMARY KEY,
varbinarycol VARBINARY(MAX),
documentExtension VARCHAR(5),
)
GO

-- The below single entry WILL BE FOUND (the text source is being entered directly)
INSERT INTO TestTable (pk, varbinarycol, documentExtension) VALUES (NEWID(), CONVERT(VARBINARY(MAX),'<META NAME="MS.LOCALE" CONTENT="EN">test entry 1'), '.html')

-- The bellow two entries below WILL NOT BE FOUND (the text source is taken from an NVARCHAR(MAX) value)
INSERT INTO TestTable (pk, varbinarycol, documentExtension) VALUES (NEWID(), CONVERT(VARBINARY(MAX), CAST('<META NAME="MS.LOCALE" CONTENT="EN">test entry 2' AS NVARCHAR(MAX))), '.html')
INSERT INTO TestTable (pk, varbinarycol, documentExtension) VALUES (NEWID(), CONVERT(VARBINARY(MAX), CAST('<META NAME="MS.LOCALE" CONTENT="EN">test entry 3' AS NVARCHAR(MAX))), '.html')
GO

-- Create the full text catalog
sp_fulltext_database 'enable'
GO
CREATE FULLTEXT CATALOG TEST AS DEFAULT
GO
CREATE FULLTEXT INDEX ON TestTable (varbinarycol TYPE COLUMN documentExtension LANGUAGE 1033)
KEY INDEX tablePK
GO

-- NOTE: You might need to give the catalog a chance to build before running the script below.

-- Now do a search that SHOULD RETURN 3 ROWS of data, but ONLY 1 ROW IS RETURNED
SELECT CAST(varbinarycol AS NVARCHAR(MAX)) FROM TestTable WHERE CONTAINS(varbinarycol, 'test')

View 10 Replies View Related

Reporting Services :: Get Computed Current Row Closing Balance Column Value In Next Row Opening Value Column

Nov 17, 2015

I have a Table Having Date,Opening,Addition,Sale values where opening value comes in the very first row other times it is zero.

In ssrs how can i have a report showing closing value = Opening+Addition-Sale  in current row (it is simple for 1st row ). this closing be the opening value in next row and same formula to be continued...

Date Opening AdditionTotalTank saleClosing Stock
01-11-15 14435 0 14435 8243 20627
02-11-15 0 15000 15000 9433
03-11-15 0 9000 9000 9436
04-11-15 0 12000 12000 8392
05-11-15 0 6000 6000 8157
06-11-15 0 12000 12000 8456
07-11-15 0 15000 15000 10903
08-11-15 0 6000 6000 8485
09-11-15 0 6000 6000 9413
10-11-15 0 21000 21000 6413

View 7 Replies View Related

Commit Fail And Transaction Log Is Full

Feb 15, 2007

Hi,

Our testing server experienced a timeout exception when execute System.Data.SqlClient.SqlTransaction.Commit() in SQL Server 2000 thru .Net Framework 1.1. And this happened at 2007-02-13 18:07:05,954.
It was strange to us that all the insert statement can be executed without error within the transaction but the commit operation fails.
Moreover, after about 40 minutes, we found that the transaction log of this database is full.

Here is the exception and SQL Server 2000 Error Log:
Exception Stack Trace:
DateTime: 2007-02-13 18:07:05,954
Req Id: bccdae08-cc47-4f85-8f48-5f0b9dbbbf88
Exception: MyDatabaseException
Detail:
MyDatabaseException:
Index #0
Server: MySQLServer
Source: .Net SqlClient Data Provider
Message: Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.
LineNumber: 0
Procedure: ConnectionRead (recv()).
State: 0
Error Number: -2 ---> System.Data.SqlClient.SqlException: Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, TdsParserState state)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning()
at System.Data.SqlClient.TdsParser.ReadNetlib(Int32 bytesExpected)
at System.Data.SqlClient.TdsParser.ReadBuffer()
at System.Data.SqlClient.TdsParser.ReadByte()
at System.Data.SqlClient.TdsParser.Run(RunBehavior run, SqlCommand cmdHandler, SqlDataReader dataStream)
at System.Data.SqlClient.SqlInternalConnection.ExecuteTransaction(String sqlBatch, String method)
at System.Data.SqlClient.SqlConnection.ExecuteTransaction(String sqlBatch, String method)
at System.Data.SqlClient.SqlTransaction.Commit()


SQL Server Error Log:

2007-02-13 13:02:23.72 backup Database backed up: Database: MyDatabaseName, creation date(time): 2007/01/12(12:01:39), pages dumped: 944769, first LSN: 9434:22326:1, last LSN: 9434:22360:1, number of dump devices: 1, device information: (FILE=1, TYPE=DISK: {'E:MSSQLBackupMyDatabaseName.bak'}).
2007-02-13 15:50:52.40 backup Database backed up: Database: MyDatabaseName, creation date(time): 2007/01/12(12:01:39), pages dumped: 944970, first LSN: 9442:38096:1, last LSN: 9443:748:1, number of dump devices: 1, device information: (FILE=1, TYPE=VIRTUAL_DEVICE: {'Legato#4f96edfd-7fdb-4cd1-a740-3fe9a54d66c6'}).
2007-02-13 18:48:51.42 spid66 Error: 9002, Severity: 17, State: 62007-02-13 18:48:51.42 spid66 The log file for database 'MyDatabaseName' is full. Back up the transaction log for the database to free up some log space..
2007-02-13 18:52:40.61 spid58 Error: 9002, Severity: 17, State: 6
2007-02-13 18:52:40.61 spid58 The log file for database 'MyDatabaseName' is full. Back up the transaction log for the database to free up some log space..
2007-02-13 18:53:22.69 spid61 Error: 9002, Severity: 17, State: 6
2007-02-13 18:53:22.69 spid61 The log file for database 'MyDatabaseName' is full. Back up the transaction log for the database to free up some log space..
2007-02-13 18:54:01.11 spid57 Error: 9002, Severity: 17, State: 6
2007-02-13 18:54:01.11 spid57 The log file for database 'MyDatabaseName' is full. Back up the transaction log for the database to free up some log space..



Are these 2 things related? Would a full transaction log cause a commit operation fail?

Please kindly advice.

Thanks a lot.

View 3 Replies View Related

PK On Computed Column

Aug 3, 2004

Maybe I am missing something very obvious, but I couldn't do it: begin trangocreate table foo (f1 int not null,f2 int not null,f3 as (f1 + f2) not null primary key clustered)gorollback trango This returns:Server: Msg 8183, Level 16, State 1, Line 8Only UNIQUE or PRIMARY KEY constraints are allowed on computed columns.

View 4 Replies View Related

Computed Column?

Apr 5, 2008

i have a table that contains 2 columns

A B (B values are only 1 and 2)
-- --
x 1
y 2
z 1
x 2
z 1
j 1
k 2

i want to make a query that will check for dinstinct x what B values it has Ex. It will show result like this

result
A B
-- --
X 1 and 2
Y 2
z 1
K 2

how to make please help

View 2 Replies View Related

Computed Column

Feb 16, 2007

I want to create computed column in table.
Suppose I have three physical column A,B and C
I want to create compute column with computed column.
A+B= X
X+C=Z
Is it possible.

View 2 Replies View Related

Computed Column

Jul 20, 2005

I created a index on a computed column. I did not see any improvementin performance with a join to this column and also my inserts andupdates to this table are failing. Any ideas?Chender

View 2 Replies View Related

Computed Column

May 22, 2008



Hi,

i have to use a datetime field in all the tables in a database as a updated timestamp.
i.e. : whenever an update happens to a row in a table, this column called LASTUPDATED has to be updated with current date time.Is there any way to implement this without using the trigger ?
can i use COMPUTED column to acheive this ?

Please help me..thnks in advance..

View 2 Replies View Related

Computed Column Question

Jun 25, 2007

I have a SQL table that maintains a field on the status of a report being completed.
I have in the record the date the report is due (DateDue)
I also have a field called DaysLate which I have set to be a calculated field with formula:
DATEDIFF(dd, DateDue, GETDATE())
Thsi works but when the report is *not* late I'd like this to be null  is there I way I can do this conditional calculation in a calculated field?
Regards
Cvive

View 2 Replies View Related

Computed Column Of A View

Jun 11, 2003

I have a view that has 2 columns. The first column is associated with a function for the Units. The second column calculates the Market Value:

View
====
Col1: Unit = get_number_of_units()
Col2: MV = get_number_of_units() * get_unit_value()

I need to call get_number_of_units() twice in the view. Is it possible to changes Col2 to something like: MV = Col1 * get_unit_value()?

Is get_unit_value() being called if I do Select Col1 from View?

Thanks.

View 1 Replies View Related

Altering A Computed Column?

Feb 27, 2008

somehow I am not able to figure this out.

How do I change a computed column using the ALTER TABLE ALTER COLUMN... command?

View 1 Replies View Related

Computed Column Issue

May 19, 2008

Hi,

I'm having a problem with a computed field in a table. I have a stored procedure that inserts a row into a table and returns the id and the computed value.
The computed colmn is returned as a decimal (29,6) but for some reason the value is returned with no decimals (confirmed by the Profiler).
The value is calculated and displayed in the database properly with decimals. Also, Is Persisted is OFF.

Below is the stored procedure, computed column foruma (both give same result), and the profiler trace.

Thanks

Stored Procedure
================================================== ==============
ALTER PROCEDURE [Purchasing].[ntp_PurchaseOrderDetail_Insert]
(
@PurchaseOrderDetailId int OUTPUT,
@PurchaseOrderId int ,
@OrderQty decimal (11, 4) ,
@VendorProductId int ,
@Description nvarchar (255) ,
@UnitPrice decimal (18, 6) ,
@PackingQty decimal (14, 4) ,
@DueDateValue nvarchar (50) ,
@ModifiedDate datetime ,
@IsUnitPriceManual bit ,
@LineTotal decimal (29, 6) OUTPUT
)
AS
INSERT INTO [Purchasing].[PurchaseOrderDetail]
(
[PurchaseOrderID]
,[OrderQty]
,[VendorVendorProductID]
,[Description]
,[UnitPrice]
,[PackingMethod]
,[PackingQty]
,[DueDateValue]
,[ModifiedDate]
,[IsUnitPriceManual]
)
VALUES
(
@PurchaseOrderId
,@OrderQty
,@VendorVendorProductId
,@Description
,@UnitPrice
,@PackingMethod
,@PackingQty
,@DueDateValue
,@ModifiedDate
,@IsUnitPriceManual
)

-- Get the identity value
SET @PurchaseOrderDetailId = SCOPE_IDENTITY()

-- Select computed columns into output parameters
SELECT
@LineTotal = [LineTotal]
FROM
[Purchasing].[PurchaseOrderDetail]
WHERE
[PurchaseOrderDetailID] = @PurchaseOrderDetailId


Computed Column Formula
================================================== ==============
isnull(CONVERT(DECIMAL (29,6),[OrderQty]*([UnitPrice]*[PackingQty])),0.000000)
or
isnull([OrderQty]*([UnitPrice]*[PackingQty]),0.000000)

Profiler Trace
================================================== ==============
declare @p1 int
set @p1=115
declare @p16 numeric(29,0) <- should be numeric(29,6)
set @p16=5 <- value should be 5.259200
exec Purchasing.PurchaseOrderDetail_Insert @PurchaseOrderDetailId=@p1 output,@PurchaseOrderId=68,@OrderQty=4,@VendorProd uctId=28,@Description=N'93678975 - GL-2222',@UnitPrice=0.657400,@PackingMethod=N'Bags (2)',@PackingQty=2.0000,@DueDateValue=NULL,@Modifi edDate=''2008-05-19 15:06:37:610'',@LineTotal=@p16 output
select @p1, @p16

View 2 Replies View Related

Using Computed Column Specification

Dec 13, 2012

I have a question about Computed Column Specification which you can specify as a formula for each column inside a table.

I have now columns named Age and Class.

Classes are "Kids" (ID #1) , "Junior" (ID #2) and "Senior" (ID #3)
Kids, which is for age of 6 till 12
Junior, which is for 12 till 16
Senior, 16 and above.

I have already searched for hours (I really did) on the internet for a solution, but ended with more questions because of the complicated solutions.

Now the Age is shown as a result of a formule of DOB (Date of Birth column), now I want the exact same thing, but the age must specify which Class the user is in.

Example, when I add a user with the birthdate 25/03/1988 (DD/MM/YYYY) he/she gets 24 as age.

With this formula : (datediff(year,[age],getdate()))

Now I want that the user gets "Senior" as Class (same table).

Senior is ID 3 in this case.

Now I do know how Case, When and Then works, but the validation fails. After reading some forums I understood that I should use a create function method. I am not really experienced with creating functions. Also the coding looks more different as I am used to. How to link the Computed Column to a created formula.

View 3 Replies View Related

Using Computed Column In The Query

Apr 14, 2004

need help ,

i have a table called "Loans" where i need to compute a column i.e. NoofDays based on which other calculation like interest calculation needs to be done.
my query goes like this

"select datediff(dd,VDate, MDate) as NoOfDays ,NoOfDays * Principal * Rate /100 * 365 from Loans".

if i run the above query it says

"Invalid column name 'NoOfDays'".

this executes fine if i use Access but not in SQL Server.

can anybody say what might be the problem and how i can solve it.

regards

Rajesh :)

View 1 Replies View Related

Problem With Computed Column

May 19, 2008

hi
i want to create a table that has a computed column like this :
create table resources(
id int identity(0,1) primary key,
currentDate int not null,
currentMonth int default 0,
monthBefore as (currentMonth - (select top 1 currentMonth from resources where (currentDate - resources.currentDate) = 1)))

as u can see, monthBefore is computed column, and i want get currentMonth value of previous month, for this work, i define a column as currentDate that hold only year+month (like 971,082,083,...) and by this expression, i want to get currentMonth of previous record (previous month), but the following error has shown me :
Subqueries are not allowed in this context. Only scalar expressions are allowed.
how to solve this problem to get currentMonth of previous record ?
thanks

View 3 Replies View Related

Formula For Computed Column

Jan 17, 2007

I have downloaded the SQL Server Books online and found the section on Computed columns. In my small banking program I have columns named Deposit/Withdrawel and Balance. If I am reading this right I need to set the Computed Column Specification of my Balance Column in order to perform the calculation. My problem now is that I have no idea how to word the formula and other than telling me what a formula is the SQL Server Books online is no help whatsoever, so any help would be awesome.

If i've misunderstood what I am meant to do somebody please please tell me. Thanks

View 3 Replies View Related

Null And Computed Column

Oct 1, 2007

how do you change the allow null on a column to be 0,
so instead of having null when empty, it would be 0,
I tried default value or binding to 0 to -1, and to 1
and in 0 or -1, it stays null, in 1 it puts the 1
for example if is quantity, it puts as if I would have 1 quantity,
so it's either null, or whathever number I put visides -1 or 0
how can I make it be 0 as defult?
I'm using it to add and substract with computed column, formula;
and the problem is that if it's the first time it's used it does not add or substract, becsause it does not add null with a number, if it has 0 than it works,
whata I had to do is add it manually, but of course it doesn't suppoesed to be that way
any suggestions will be appriciated:

View 2 Replies View Related

Computed Column Calculations

Jul 23, 2005

If i want to split a computed column into two or more columns based onthe the length (its a varchar) of the computed column, how often willsql server determine what the computed column is? roughly along thelines ofselect comp_col,'comp_col 2'=case when datalength(comp_col)<=100 then comp_colelse left(comp_col,99) + '~' end,datalength(comp_col)from aTableAs you can see, in this scenario we use the computed coulumn,comp_col, in a few places, so does SQL server need to calculate thiseach time? I'm playing with this on the basis that it does and thustrying to shift the computed column out to a variable and thenmanipulte and return from their, but that has its own problems whenyou throw in additional parameters (trying to join table udf's) so ifSQL server is smart enough to not calculate the column each time Iwould save a lot of hassle?Cheers Dave

View 9 Replies View Related

Index Computed Column?

Jul 28, 2006

Can I create an index on a variation of a column that isn't actually inthe table?I have a ParcelNumber column, with values like123 AB-67012345ABC 000-00-04012-345-67AP34567890The blanks and non-alphanumeric characters cause problems with users,because sometimes they're there, and sometimes they aren't. So I wouldlike to create an index based on this column, with the non-alphanumericcharacters squeezed out. Of course I can add such a column to thetable and index it, but I'm wondering if it can be done withoutactually adding the column.Thanks,Jim

View 6 Replies View Related

Computed Column Specification

Sep 10, 2006

Hello,I want to assign a column a computed value, which is the multiplicationof a value from the table within and a value from another table.How can I do that?Say the current table is A, column1; and the other table is B, column3.What should I write as formula?I tried someting like;column1 * (SELECT column3 FROM B WHERE A.ID = B.ID)but it didn't work.

View 2 Replies View Related

Problem With Computed Column

May 19, 2008

hi
i want to create a table that has a computed column like this :

Code Snippetcreate table resources(id int identity(0,1) primary key,currentDate int not null,currentMonth int default 0,monthBefore as (currentMonth - (select top 1 currentMonth from resources where (currentDate - resources.currentDate) = 1)))

as u can see, monthBefore is computed column, and i want get currentMonth value of previous month, for this work, i define a column as currentDate that hold only year+month (like 971,082,083,...) and by this expression, i want to get currentMonth of previous record (previous month), but the following error has shown me :

Code SnippetSubqueries are not allowed in this context. Only scalar expressions are allowed.
how to solve this problem to get currentMonth of previous record ?
thanks

View 11 Replies View Related

Computed Column And Cursor

Dec 26, 2007

Is it possible to use a cursor in computed column?

I have two table (Table1 and Table2). Table 2 is child of Table 1.

Table 2 has more than one record for each record in table 1. What I want is, to concat records from table 2 and show it as a column value for Table1.

e.g.


Code Block
Table 1:
Col1 Col2
1 ABC
1 DEF

Table 2
T1Col1 Col2
1 A
1 -
1 B
1 1
1 -
1 C
I want to see the Results as
Table 1
Col1 Col2 Col3
1 ABC A-B1-C


Is it possible to add computed column for the table1 to get the result as shown in above block.

Thanks

View 3 Replies View Related

It's A Computed Column Processing Bug?

Sep 25, 2007



Hello everybody!

I have question about indexed and not indexed Persisted columns on sql server 2005. It's a bug?

First?, my version of SQL Server is
Microsoft SQL Server 2005 - 9.00.3186.00 (Intel X86) Aug 11 2007 03:13:58 Copyright (c) 1988-2005 Microsoft Corporation Developer Edition on Windows NT 5.1 (Build 2600: Service Pack 2)


Now I create two tables and try four select queries:


Code Snippet
SET ANSI_NULLS ON
SET ANSI_PADDING ON
SET ANSI_WARNINGS ON
SET ARITHABORT ON
SET CONCAT_NULL_YIELDS_NULL ON
SET NUMERIC_ROUNDABORT OFF
SET QUOTED_IDENTIFIER ON
GO
create table t1 (id int primary key, id_bigint as cast(id as bigint))
GO
create table t2 (id int primary key, id_bigint as cast(id as bigint) persisted)
GO
select * from t1 -- (1)
-- Clustered index scan with two times Compute Scalar
GO
select * from t2 -- (2)
-- Clustered index scan with one times Compute Scalar
GO
create index IX_t2 on t2 (id_bigint)
GO
select * from t2 -- (3)
-- Index Scan with one times Compute Scalar
GO
select * from t2 where id_bigint = 0 -- (4)
-- Index Seek with one times Compute Scalar
GO
drop table t1
GO
drop table t2
GO
SET ANSI_PADDING OFF



1. I don't understand why access to computed column raise scalar computation wto times?
2. I don't understand why access to persisted computed column raise any scalar computation?
3. I don't understand why access to persisted computed column over index required any scalar computations?

Can anyone from Microsoft SQL Server Team told me about this mistake?
It's a BUG or I incorrect understand value of the "PERSISTED" word?


--
Thanks with avanced.
WBR, Roman S. Golubin
grominc[at]gmail.com

View 3 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved