Showing posts with label values. Show all posts
Showing posts with label values. Show all posts

Thursday, March 29, 2012

getting the number of records with like values

I have a resultset that looks something like this:

Anzahl users_statdata_hobbies

499 Andere
266 Essen
60 Essen,Andere
127 Essen,Musik
10 Essen,Musik,Party,Andere
30 Essen,Party
4 Essen,Party,Andere
51 Kunst
4 Kunst,Andere
13 Kunst,Essen
4 Kunst,Essen,Andere

I get this with this query which might be altered somehow:
SELECT COUNT(*) AS Anzahl, users_statdata_hobbies
FROM vgetAuswertung2
GROUP BY users_statdata_hobbies
ORDER BY users_statdata_hobbies

Of course this is not normalized but I can't change this.

Nevertheless I need to get the full number of each Hobby and not only the combination of them.

So instead or in addition to the existing recordset I need e.g

357 Essen which ist the sum of all records containing 'Essen' in the above example

The list of individual hobbies is defined therefor I could loop through the list manually and search for 'WHERE Hobbies LIKE '%ESSEN%' and count but since it's quiet a big resultset and there are several other similar tasks already I'm looking for a more performant way and I'm sure it could be done in SQL directly.

Any ideas someone?

You could perform the initial select into a temp table, then count on that table.

For example:

SELECT into #temp COUNT(*) AS Anzahl, users_statdata_hobbies
FROM vgetAuswertung2
GROUP BY users_statdata_hobbies
ORDER BY users_statdata_hobbies

Select sum(Anzahl), substring(users_statdata_hobbies, 1, 5)

from #temp

group by substring(users_statdata_hobbies, 1, 5)

drop table #temp

You may need to play with conversion or cast on the first column if implicit conversion won't use it as an integer.

Martin

|||

I think your best bet is writing a Table-valued user-defined function that receives in two variables, a delimited list and the delimiter character. Then split the values (i.e. Essen,Musik,Party,Andere) into a returned table. You can then either insert all your results into a temp table and count or you can use relationships with your Master Hobby table to get your counts. The benifit is you get exact counts for each of the Hobbies, not just Essen, which in my mind is like planning ahead for what you might need later.

Good luck.

|||

Hello,

I would consider splitting up the Hobby table. You should create one record per Hobby. This will make selecting and joining those records MUCH more efficient. It might look like a lot of work at first, but such a design would also allow comparisons across languages if you think about multi-language websites later on. And it will also make it possible to extract a exact number of "matching hobbies" in a single querry.

Another "problem" with storing the hobbies in a string like that would be indexing.Also is "Wein,Weib,Gesang" the same as "Gesang,Wein,Weib"? Any querry using a "like '%bla%'" wont be able to use an index on the table. The result would be that you have to scan ALL records for every time someone is searching for a "match"... And since that is most likely one of the main functions of your site, you should try to keep it as efficient as possible.

Getting the matching columns from two tables

Hi all..
I have two tables such as cisco and ciscocom. and i wan to compare each
row of ciscocom with cisco having same column values. i wan to get the
count of matching columns for each row in cisco...
eg:
Ciscocom has columns: Products,fw,ports,sec,des,tput etc and cisco has
columns:fw,ports,sec,des,tput etc. i wan the number of matching colum
for each row in ciscocom. please provide me with the procedure...
Waiting for your response...On 1 Mar 2006 03:03:08 -0800, vvyshak@.gmail.com wrote:

>Hi all..
>I have two tables such as cisco and ciscocom. and i wan to compare each
>row of ciscocom with cisco having same column values. i wan to get the
>count of matching columns for each row in cisco...
>eg:
>Ciscocom has columns: Products,fw,ports,sec,des,tput etc and cisco has
>columns:fw,ports,sec,des,tput etc. i wan the number of matching colum
>for each row in ciscocom. please provide me with the procedure...
>Waiting for your response...
Hi Kuttan,
I just answered this question in microsoft.public.sqlserver.programming.
Please don't post seperate copies of the same question to several
groups!
Hugo Kornelis, SQL Server MVP

getting the matching columns from two tables

Hi all..
I have two tables such as cisco and ciscocom. and i wan to compare each
row of ciscocom with cisco having same column values. i wan to get the
count of matching columns for each row in cisco...
eg:
Ciscocom has columns: Products,fw,ports,sec,des,tput etc and cisco has
columns:fw,ports,sec,des,tput etc. i wan the number of matching colum
for each row in ciscocom. please provide me with the procedure...
Waiting for your response...Try something like this:

SELECT COUNT(cisco.Products) FROM cisco INNER JOIN ciscocom
ON cisco.Products = ciscocom.Products
WHERE
cisco.Products='My_Value'|||On 1 Mar 2006 03:04:35 -0800, vvyshak@.gmail.com wrote:

>Hi all..
>I have two tables such as cisco and ciscocom. and i wan to compare each
>row of ciscocom with cisco having same column values. i wan to get the
>count of matching columns for each row in cisco...
>eg:
>Ciscocom has columns: Products,fw,ports,sec,des,tput etc and cisco has
>columns:fw,ports,sec,des,tput etc. i wan the number of matching colum
>for each row in ciscocom. please provide me with the procedure...
>Waiting for your response...

Hi Kuttan,

I just answered this question in microsoft.public.sqlserver.programming.
Please don't post seperate copies of the same question to several
groups!

--
Hugo Kornelis, SQL Server MVPsql

Getting the matching columns from two tables

Hi all..
I have two tables such as cisco and ciscocom. and i wan to compare each
row of ciscocom with cisco having same column values. i wan to get the
count of matching columns for each row in cisco...
eg:
Ciscocom has columns: Products,fw,ports,sec,des,tput etc and cisco has
columns:fw,ports,sec,des,tput etc. i wan the number of matching colum
for each row in ciscocom. please provide me with the procedure...
Waiting for your response...On 1 Mar 2006 03:03:08 -0800, vvyshak@.gmail.com wrote:
>Hi all..
>I have two tables such as cisco and ciscocom. and i wan to compare each
>row of ciscocom with cisco having same column values. i wan to get the
>count of matching columns for each row in cisco...
>eg:
>Ciscocom has columns: Products,fw,ports,sec,des,tput etc and cisco has
>columns:fw,ports,sec,des,tput etc. i wan the number of matching colum
>for each row in ciscocom. please provide me with the procedure...
>Waiting for your response...
Hi Kuttan,
I just answered this question in microsoft.public.sqlserver.programming.
Please don't post seperate copies of the same question to several
groups!
--
Hugo Kornelis, SQL Server MVP

Getting the matching columns from two tables

Hi all..
I have two tables such as cisco and ciscocom. and i wan to compare each
row of ciscocom with cisco having same column values. i wan to get the
count of matching columns for each row in cisco...
eg:
Ciscocom has columns: Products,fw,ports,sec,des,tput etc and cisco has
columns:fw,ports,sec,des,tput etc. i wan the number of matching colum
for each row in ciscocom. please provide me with the procedure...
Waiting for your response...
On 1 Mar 2006 03:03:08 -0800, vvyshak@.gmail.com wrote:

>Hi all..
>I have two tables such as cisco and ciscocom. and i wan to compare each
>row of ciscocom with cisco having same column values. i wan to get the
>count of matching columns for each row in cisco...
>eg:
>Ciscocom has columns: Products,fw,ports,sec,des,tput etc and cisco has
>columns:fw,ports,sec,des,tput etc. i wan the number of matching colum
>for each row in ciscocom. please provide me with the procedure...
>Waiting for your response...
Hi Kuttan,
I just answered this question in microsoft.public.sqlserver.programming.
Please don't post seperate copies of the same question to several
groups!
Hugo Kornelis, SQL Server MVP

getting the latest datetime

Hi

I have a DateTime column in my table, and I want to select the first couple of rows whose DateTime values are closest to the currect serve rdatetime. Is there a function like Max() that I can use?

Also, quesion about timestamp. If I create a column of type timestamp, is the value automatically entered by the database on every insert entry to the table?
I have had problems using timestamp so I switched to using datetime now.

Help appreciated!For the first part of your question, I would use the DATEDIFF() function to find the difference between the current date (GETDATE()) and the date value stored in your column, sorted in DESC order, taking the TOP 1 or 2 (however many you want).

The Timestamp data type is actually a unique rowversion containing binary/varbinary data, and its value only has meaning to SQL Server itself. SQL Server updates the value in this column upon every INSERT, UPDATE, and DELETE. You could make use of this Timestamp value for concurrency control, but it does not contain datetime data -- it contains binary/varbinary data.

Terri

Tuesday, March 27, 2012

Getting the Id of the row that i inserted with SQL 2005

Hi,

I use a Stored Procedure who works very well

...
INSERT INTO Computers (CategoryID, SubCategoryID, .....
VALUES (@.CategoryID, @.SubCategoryID, ....
...

But as soon as it creates the new row, i want to be able to get the Id (ComputerId) of this row. I use ComputerId as the primary key.

How can i do that? I code in VB.

Thanks

Add "RETURN SCOPE_IDENTITY()" to your stored procedure. Then you should be able to pick up this value as the stored procedure's return value.

|||

Thank you very much it works!

Getting the data associated with a (known) member

Greetings SSAS-ters,

Specifically, If I know the member (e.g. [DimensionX].[AttributeY].&[46E2]) whose values I am trying to get at, how do I get at that member's actual values.

Generally, this is an org. chart type parent-child hierarchy, and for everyone* (i.e. for each [DimensionX].[AttributeY].currentmember) in the hierarchy, I need to know their top-level manager's name, their 2nd-from-top-level manager's name, and so on.

Syntactically, I'm getting at the currentmember using:

subset(

hierarchize(

ascendants(

[Producer Hierarchy].[Agency Producer Name And Payroll Number - multicolumn].currentmember

) /* )ascendants */

) /* )hierarchize */

,1 /*subset startposition....*/

,1 /*...subset for 1 member in set....*/

) /* )subset */

I'd appreciate any help - thanks in advance!!

Gregg

Please note - I am wanting to SCOPE my result within a CREATE MEMBER CURRENTCUBE.[MEASURES].MyNewMeasure cube calculation, please.|||

In case anyone ever needs the same info, this problem eventually got figured out and solved by using:


ancestor([parent-child-hierarchy], <<numeric expression>>).name

getting textbox to show all values

Is there a way in rs to have a textbox more than the first value when it is dragged on the rs form when creating a report? currently when I drag a text box on the rs form, it only shows the first record on a page/form. There are twenty records on the table where the first value came from. How can I make so that twenty text boxes representing twenty records appear on twenty different pages. In other words, I am trying to build a report with a non - tabular structure that can repeat on different pages.

Drag a list from the toolbox to your report. Place that textbox inside that list. Right click on the List and go to Properties and select the dataset from the list for "Data set name" field.

If your field name is Field1, use this expression in the textbox =Fields!Field1.Value

Then right click on your list and go to Properties and check the box against "Insert a page break after this list"

Shyam

|||Thanks Shyam. worked fantastic! Just what I was looking for.|||

Can you please mark my post as answer?

|||

Hi Shyam!!

I am trying to do something similar but i dont get it: i would like to show a list of computers in a textbox but i have each computer in a different row of the dataset... if i put a list, i have each computer in a different textbox and that is not what i am looking for...

Can u help me? Thanx in advance!!!

Sergi

getting textbox to show all values

Is there a way in rs to have a textbox more than the first value when it is dragged on the rs form when creating a report? currently when I drag a text box on the rs form, it only shows the first record on a page/form. There are twenty records on the table where the first value came from. How can I make so that twenty text boxes representing twenty records appear on twenty different pages. In other words, I am trying to build a report with a non - tabular structure that can repeat on different pages.

Drag a list from the toolbox to your report. Place that textbox inside that list. Right click on the List and go to Properties and select the dataset from the list for "Data set name" field.

If your field name is Field1, use this expression in the textbox =Fields!Field1.Value

Then right click on your list and go to Properties and check the box against "Insert a page break after this list"

Shyam

|||Thanks Shyam. worked fantastic! Just what I was looking for.|||

Can you please mark my post as answer?

|||

Hi Shyam!!

I am trying to do something similar but i dont get it: i would like to show a list of computers in a textbox but i have each computer in a different row of the dataset... if i put a list, i have each computer in a different textbox and that is not what i am looking for...

Can u help me? Thanx in advance!!!

Sergi

Monday, March 26, 2012

Getting started with phonetic comparisons

I've been reading a bit about full-text searches, phonetic values and match-queries and just don't know where to begin.

What I'm eventually going to do, is make procedures for matching names, finding records that are close matches and presenting them in a subform below the actual member that you look up.

E.g. if an employee looks up Sergej, he or she will also see Sergey, Sergei etc. below the membersheet.

BOL isn't very practical in examples, and its about 7 years since I took my SQL-Server 7.0 MS courses, plus I've primarily worked as an administrator up until last fall, not a developer. So where to begin?

Thanks in advance,

TrinTwo functions in this attachment.

Function COMPARETEXT() evaluates all the character pairs in two strings and returns a numeric value between 0 and 100 indicating the degree of similarity between the strings.

Function MATCHTEXT() strips vowels and non-alphanumeric characters from a string to create a "matchstring" that can be passed to COMPARETEXT for more accurate comparisons.

I have used these two functions to indentify duplicate records for ten years now. The most effective method is to create a permanent column of matchtext strings in your table, so as to prevent having to recalculate them. Then pass the string you want to compare through MATCHTEXT() prior to submitting it as a parameter to COMPARETEXT along with the data in your table.

Generally, a returned value of over 80 indicates a match. Anything between 60 and 80 is worth having a human review. Also, the process goes faster if you can first match records on some other factor, such as zip-code.|||Man, this looks positively awesome. I've been looking at different approaches, and comparetext combined with the SQL function Difference will positively do for my situation of comparing names.

Very slick and easy functions you've made there. Probably not easy to invent, but easy to understand.

Thanks a bunch. Your name resides in another sql-server installation on the world :)

Cheers, Trinsan|||Thanks a bunch. Your name resides in another sql-server installation on the world
You don't work for the CIA, I hope...

Thanks for the kudos.sql

Wednesday, March 21, 2012

Getting rid of 'NaN' values in the Graph

Hi folks,

I run into problems where some metrics have value associated with dim attributes Markets where some don't have... The graph shows NaN, in the reporting services. Is there a way to get of NaN. something like filter out.

--Imran

Use the dataset filters and the following filter expressions:

CStr(Fields!YourField.Value) <> "NaN" AND

Fields!YourField.Value <> Nothing

Shyam

Getting Rid of DBNull values in DB

As a part of migration to .net we are redesigning sql server 7 database and moving it to sql server 2005. There are a lot of fields with dbnull value in the existing db. It would be nice to populate them with some default value while transfering data to the new datbase on sql server 2005.

What is the best way to deal with the issue, are there any possible drawbacks and problems.

Your input will be greatly appreciated.

Getting rid of NULLs/having default values is generally a good thing. It removes a lot of overhead in your code to constantly check for NULLs. You can write UPDATE queries to update the NULLs to some default values. A sample update query could be:

UPDATE yourTable SET Price = 0 WHERE Price IS NULL

sql

getting rid of comma separated column data

working on a transformation, and one of the things i'm trying to get
rid of are columns with comma separated values as lists of data. my god
is that annoying.
anyway, i need an insert and/or update query that will break up the
following comma value problem example (keyword being example, please
don't XXXXX about keys or relationships, it really has nothing to do
with my question):
create table foo (
fooid int identity(1, 1) not null ,
foolistofthingoldids varchar(500)) -- relate to thingoldid
create table things (
thingoldid int identity(1, 1) not null ,
thingnewid uniqueidentifier not null)
-- and this is the new table to replace the comma values in foo
create table foothings (
fooid int not null,
thingnewid uniqueidentifier not null)
it should be noted that i have a user defined split function that can
turn a comma separated list of values into a single column table, with
one row per comma separated item.
the trick is finding a way to use it in a set based operation to fill
foothings with rows, based on the relationships implied in the current
foo table's foolistofthingoldids property. i'm looking for something
like this:
INSERT INTO foothings (fooid, thingnewid)
SELECT f.fooid, t.thingnewid
FROM foo AS f
RIGHT JOIN split(f.foolistofthingoldids, ',') AS l
RIGHT JOIN things AS t ON l.value = t.thingoldid
except, one that actually compiles and works. but this is a sketch of
where i have been leading my train of thought.
thanks in advance for any help!
jasonCourtesy of Kass:
http://www.users.drew.edu/skass/sql...unction.sql.txt
-oj
"jason" <iaesun@.yahoo.com> wrote in message
news:1128945919.133895.197370@.g47g2000cwa.googlegroups.com...
> working on a transformation, and one of the things i'm trying to get
> rid of are columns with comma separated values as lists of data. my god
> is that annoying.
> anyway, i need an insert and/or update query that will break up the
> following comma value problem example (keyword being example, please
> don't XXXXX about keys or relationships, it really has nothing to do
> with my question):
> create table foo (
> fooid int identity(1, 1) not null ,
> foolistofthingoldids varchar(500)) -- relate to thingoldid
> create table things (
> thingoldid int identity(1, 1) not null ,
> thingnewid uniqueidentifier not null)
> -- and this is the new table to replace the comma values in foo
> create table foothings (
> fooid int not null,
> thingnewid uniqueidentifier not null)
> it should be noted that i have a user defined split function that can
> turn a comma separated list of values into a single column table, with
> one row per comma separated item.
> the trick is finding a way to use it in a set based operation to fill
> foothings with rows, based on the relationships implied in the current
> foo table's foolistofthingoldids property. i'm looking for something
> like this:
> INSERT INTO foothings (fooid, thingnewid)
> SELECT f.fooid, t.thingnewid
> FROM foo AS f
> RIGHT JOIN split(f.foolistofthingoldids, ',') AS l
> RIGHT JOIN things AS t ON l.value = t.thingoldid
> except, one that actually compiles and works. but this is a sketch of
> where i have been leading my train of thought.
> thanks in advance for any help!
> jason
>|||Take a look at:
http://www.sommarskog.se/arrays-in-sql.html

> don't XXXXX about keys or relationships, it really has nothing to do
> with my question):
What is the point of writing something like that rather than just
posting the keys and constraints? To pretend that keys have nothing to
do with a problem in SQL is like saying that foundations have nothing
to do with building a house. Keys are fundamental to any data
manipulation problem. I can't figure out much just from a list of
column names and many people probably won't bother to try so I
recommend that if you want a fuller answer you include primary and
foreign keys at least.
David Portas
SQL Server MVP
--|||hmm, maybe i wasn't clear. i already have a user defined function to do
the table creation from comma separated list. i'm just having trouble
with how to use it in the statement i listed.
but the link is useful for the user defined function sers, thanks.|||i find it burdensom and unnecessary, in recreating a simplified version
of a schema to solve something syntactic. at least in some cases. in
this specific case, i'm simply struggling with how to make use of a
user defined function to get data out of an aribitrary comma separated
list, and into a column on another table.
i've read the link you posted several ws ago to come up with the
user defined function that i already mentioned having. perhaps i was
not clear with my question, but i don't need the creation of a table
from a comma separated value. i've had and used that function for a
little while now.
currently i'm trying to figure out how to make use of it in this
specific set-based statement.|||What you're asking for is a recursion. You can do so in sql2k as a cursor or
CTE in Yukon.
-oj
"jason" <iaesun@.yahoo.com> wrote in message
news:1128947946.090802.222680@.f14g2000cwb.googlegroups.com...
> hmm, maybe i wasn't clear. i already have a user defined function to do
> the table creation from comma separated list. i'm just having trouble
> with how to use it in the statement i listed.
> but the link is useful for the user defined function sers, thanks.
>|||i'll look up those topics, thanks. do you have any links or other
keywords that might propel me on my search?|||In the absence of any proper data structure to work with, here's a
solution to a similar problem that may help you:
http://groups.google.co.uk/group/mi...c314d5ea4ef14f5
David Portas
SQL Server MVP
--

Monday, March 19, 2012

Getting rid of 0 and 'NaN' values in my report?

Hello,

I have a report produced by RS 2005. And I am wondering if there is a way to not display values that are '0' or 'NaN'. It also applies to calculated fields which are displayed as percentages and I don't want to have '0%' or 'NaN' for those columns as well. Any help is greatly appraciated.

Thanks

Quick and dirty fix is to write the expression.

Select the required report item (text box)

Choose expression for property <Value>

=iif(Fields!FieldName.Value=0,"",Fields!FieldName.Value)

|||Thanks for the answer.

Getting Return type from Stored Procedure

Hi all,

I am trying to figure out a way to analyze a stored procedure to deduce its output type.

A stored procedure can return values throught one of the following:

1) Using the Return keyword

2) Returning a recordset

3) Throught its Output parameters

4) A combination of 1, 2 or 3

Using the Information_Schema, you can access the SQL code of the stored procedure from, say, VB.Net. From there, I want to know what output type the stored procedure has.

A) for 1), I guess I can parse the code for the 'Return' keyword, but that wouldn't be efficient, for the 'Return' word could be inserted into string values...

B) for 2), it would be difficult to analyze the stored procedure's code to know FOR SURE whether a recordset is returned. You just can't parse for SELECT keywords in complex code...

C) 3) should be easy enough, getting the return parameters types from the Information_Schema.

So, is there an easy way that I missed for achieving this, some object in the .Net Framework that I could use to analyze SQL queries perhaps, or am I doomed to do it the hard way?

Thanks,

-Etienne

1) Always integer

2) Recordsets are too dynamic, so there is no metadata about them until you execute. You could say:

if (1=@.value)
begin
select 'hi' as gibberish
end

and the output not be known until runtime

3) You are correct, this information is in information_schema/sys.parameters

|||

Thanks for your input,

1) Yes the Return type would be always integer, but I wouldn't know that until I actually executed the stored procedure.

I agree with you on point 2) and 3)...

I was wondering about eventual .Net Framework (or internet open source code) objects that could analyze and structure a SQL query and give you info about it. Would anybody know of such objects?

|||No, I mean for number 1 the only type you can return using RETURN in a stored procedure is an integer :) That is the only type that is allowed.|||

The data is analyzed within the sp_

If my data is correct then return 1 else return 0

Adamus

|||

I probably didn't express myself correctly.

I meant that I needed to know whether 1) or 2) or 3) is the case in a stored procedure, not what type the Return statement gets (yes, it's always integer).

Given the SQL code of a stored procedure, how do I know whether

1) a Return value is returned or

2) whether a Select statement is returned or

3) a parameter set as Output is returned

without having to execute the code.

As discussed, we already got 3) under control, and 1) and 2) could be solved by parsing the SQL code and analyzing it.

I was just wondering whether a better way to analyze a Stored Procedure code exists than me doing it by hand.

'Hope this unfogs the issue.

|||

Sorry :) You can't tell programatically because a value is always returned. If you don't use a return statement, it return 0:

create procedure testReturnValue
as
select 'hi'
go

declare @.retval int
exec @.retval = testReturnValue

select @.retval


-
hi


--
0

|||

It can be 1,2 AND 3 at the same time, take alook at this

CREATE procedure SomeProc
@.CompanyName varchar(100),
@.UserID int output
as

set nocount on

select @.UserID = 1


select @.UserID

return @.UserID


set nocount off

GO

--

declare @.UID int, @.i int
exec @.i = SomeProc 'blah', @.UID OUTPUT

select @.i,@.UID

the proc returns a value, has a select and also an output parameter

Denis the SQL Menace

http://sqlservercode.blogspot.com/

Monday, March 12, 2012

Getting previous values of a field

Hi,

In oracle I have a LAG function using which I could get the previous
value of a field.
Do we have anything similar to that in SQL Server or access?

Thanks

Devidevi (devivelu@.gmail.com) writes:
> In oracle I have a LAG function using which I could get the previous
> value of a field.
> Do we have anything similar to that in SQL Server or access?

I have no idea what LAG does in Oracle, but the only place you can
retrieve this information easily is when you are in an UPDATE or
DELETE trigger, in which case you find the information in the
virtual table "deleted". One the transaction is committed, the only
way to retrieve the information is through a log-reader tool.

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx|||Sorry. I guess I wasnt clear in explaning my doubt...

I am creating a simple bug tracker application (in Access db) and i
created a hisotry table to
log the bug history.

The history table contains details like ProblemRecordNo (PRN),
RecordStatus, Assignee, Reporter (and also some more columns). The PK
for this table is ID. It contains multiple entries for a Record.

I have inserted a lot of records int History table and now I introduced
two new fields into History table. They are PreviousStatus and
PreviousAssignee. I wanted to update the previous values of the Status
and Assignee for each record.

Say my History table contains values like

ID PRN Status Assignee
1 10 Report UserA
2 10 InProcess UserA
3 10 Esclated UserB

Now after introducing the Previous fields, the History table should
look like

ID PRN Status Assignee PreviousStatus PreviousAssignee
1 10 Report UserA
2 10 InProcess UserA Report UserA
3 10 Esclated UserB InProcess UserA

In the first record the PreviousStatus and PreviousAssignee are empty
bse there is no previous values for those two items. the next two
records contain the previous values of the status and assignee.

I used the following sql statement to update the table, but I get a
script time out error

UPDATE (
SELECT H.PRN, H.ID, H.PREVIOUSSTATUS AS OLDSTATUS, N.STATUS AS
NEWSTATUS,
H.PREVIOUSASSIGNEE AS OLDASSIGNEE, N.ASSIGNEE AS NEWASSIGNEE FROM
HISTORY H,
(SELECT N.ID, N.PRN, N.STATUS, N.ASSIGNEE FROM HISTORY N ) N
WHERE H.PRN = N.PRN AND N.ID < H.ID AND N.ID IN
(SELECT MAX(M.ID) FROM HISTORY M WHERE M.ID < H.ID AND H.PRN = M.PRN) )
SET OLDSTATUS = NEWSTATUS,
OLDASSIGNEE = NEWASSIGNEE

Is there anyother way i could update the table with a optimized query
that doesnt take time to update large set of rows.

:(|||devi (devivelu@.gmail.com) writes:
> I am creating a simple bug tracker application (in Access db) and i
> created a hisotry table to
> log the bug history.

In such case you should ask in comp.databases.ms-access. While both
SQL Server and Access are produced by the same Redmon company, there
are vast differences between the SQL dialects.

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx|||Can you access LAG in PL/SQL? I thought is was a datamining function. It is
also available in SQL Server Analysis services.

--
Anith

Getting Parameter Values - Need Perspective

Have several server reports (RDLs, not RDLCs) that use report parameters (text boxes, dropdowns, etc). Is it possible to view these reports in web pages using the report viewer control and use the report parameters as they were originally intended?

From what I've experienced so far, reports behave as if parameter data was not entered. I've tried to extract parameter values, but only know how to find the parameter metadata.

Do I need to hide the report parameters and substitute them with visible web controls instead? I know how to programmatically set the report parameters, just don't know the best, if not the only way to extract user input.

See Bill Vaughn's reply in MSDN Forums >> Visual Studio >> Visual Studio Report Controls >> Getting Parameter Values - Need Perspective.

Getting OUTPUT parameter in an OLE DB Command

Is it possible to use stored procedure with output parameter and retrieves the values of that output parameter, in an OLE DB Command within a Data Flow?

What I wanted to do is to get the newly created identity of a row so that I can insert it to the main data set in data flow. I'm not even sure if there is even a much better design to achieve this. I've rummaged the internet but everything I got were all about Execute SQL Task.

Rather than using the OLE DB Command to get the identity column value (which is going to be significantly slower than inserting through an OLE DB Destination), have you considered generating your own keys in the data flow? There's an example here: http://www.ssistalk.com/2007/02/20/generating-surrogate-keys/ and here: http://www.sqlis.com/37.aspx, plus numerous posts on the forum.|||

Hi jwelch. I will be perusing those sites soon. Regarding key generation, I'm relying on IDENTITY columns so I'm afraid this is not an option for me unless those sites will prove otherwise. Thanks for the reply

|||I discovered that this is not the most optimized way of achieving my goal so I abandoned this one. Unfortunately, I encountered another showstopper which you can find more about here --> http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1877437&SiteID=1|||

u_r_twisted wrote:

Regarding key generation, I'm relying on IDENTITY columns so I'm afraid this is not an option for me unless those sites will prove otherwise. Thanks for the reply

Gosh, I HATE identity columns. They are a pain in the rear to work with.... Nice for some things, but when doing ETL they stink. When you look at the link at my site above (ssistalk.com) that John linked to, I have a small discussion on why using identity columns is not preferred.

Friday, March 9, 2012

Getting nulls in SQL2005 table while importing from EXCEL spreadsheet

I am trying to import an Excel Spreadsheet into SQL2005. There is a column in the spreadsheet that has character values, and numbers. I have formatted the numbers as text on the spreadsheet. I have declared the column on the table as char/varchar/nchar, but whatever I do, the numbers don't get imported into the table, but show up as nulls. Any idea why?

Thanks

Mangala

Search the forum. It's a common issue.

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1872950&SiteID=1