Rownum Alternate In MS-SQL
Jul 17, 2007
I want to get 100 rows from particular record and onward. in oracle i can use rownum and in mySql i have function limit ... i want to know what is the ms-sql alternate for it.
I want to get 100 rows onward to one particular data ... how can i ?
View 9 Replies
ADVERTISEMENT
Nov 10, 2004
Hi folks,
SELECT * FROM mytable
100 rows returned.
Can i get a rownum column for each record; i.e. if 100 records returned; rownum order 1,2,3.....100 along with the each record position.
is it possible without using cursor?
Howdy!
View 4 Replies
View Related
Dec 1, 2005
Does SQL Server 2005 or SQL Express have the capability of the ROWNUM function found in Oracle (LIMIT in MySQL)?please advice!To select records from row #10 to row #20Oracle: SELECT * FROM MyTable WHERE ROWNUM>9 AND ROWNUM<21MySQL: SELECT * FROM MyTable LIMIT 10,20SQL Server: ?
View 3 Replies
View Related
Aug 16, 2004
Hi,
Rownum returns the serial number for the records in Oracle.
Id there an equivalent for the same in SQL Server ?
select rownum from test_table;
Please advise,
Thanks
Sam
View 1 Replies
View Related
Nov 13, 2007
hai, for one of my batch requirement i would like to retrieve records set by set, meaning if there are 1000 records which satisfies the condtion, i want to take first 100 record process it, and then again go to database retireve another 100 record and so on...
how can i do this...do i need use the for loop logic or, is there any simple way to achieve this? help pls
View 3 Replies
View Related
Mar 19, 2008
Background: SQL Server 2000 transactional database
Key fact 1: I have one main fact table and several dimension tables. for each join between a dimension table and the fact table, I have a combined key that includes at least three fields one of which would be a date field.
Key fact 2: Sometimes fields in the dimension tables changes names over time e.g. a department that was called dept_1 a few years ago might have changed its name since and is now called dept_A today. The historic report should still use today's name of the department.
For example using three tables (keys are colour coded)
DEPT table and JOB table and Employee table
DEPT_table JOB_table EMPLOYEE_table
DEPTID DEPTID EMPLID
SETID DEPT_SETID EMPL_RCD
EFFDT EFFDT
DESCR_LONG EFFSEQ
DESCR_SHORT EMPLID
EMPL_RCD
Since departments change names over time, I intend to return just the most current department name for use in my reports but one way or another SOME records return more than one. I am using max(effdt) to extract the most recent from two tables like the ones above.
Code Snippet
DEPT_TBL.DEPTID=BO_JOB_VW.DEPTID and DEPT_TBL.SETID=BO_JOB_VW.SETID_DEPT and
DEPT_TBL.EFFDT=(select max(j.EFFDT) from DEPT_TBL j where
j.EFFDT<=BO_JOB_VW.EFFDT and
j.DEPTID=BO_JOB_VW.DEPTID and
j.SETID=BO_JOB_VW.SETID_DEPT)
and
Code Snippet
BO_JOB_VW.EMPLID = EMPLOYEE.EMPLID
BO_JOB_VW.EMPL_RCD = EMPLOYEE.EMPL_RCD
Although it is possible for an employee to belong to more than one department simultaneously, what I have notice is that for some employees that get multiple rows of departments, they have never belonged to more than one department or ever changed departments at all.
e.g
Code Snippet
DEPT
/*
DEPTID SETID EFFDT DESCR
DP1 GBR 01/01/1901
DP1a GBR 01/01/1965
DP2 GBR 01/01/1996
DP2a GBR 01/01/1998
DP2b GBR 01/01/2006
*/
DP1 and DP1a refers to the same department but reflect a change of names
DP2, DP2a and DP2b refer to one department but also reflect changes in the name
JOB
/*
DEPTID SETID EFFDT EMPLID EMPL_RCD EFFSEQ STD_HRS
DP1 GBR 01/01/1901 001 0 0 37.0
DP1a GBR 01/01/1999 002 0 0 37.5
DP2 GBR 01/01/1996 003 0 0 18.75
DP2a GBR 01/01/1998 003 0 1 22.2
DP2b GBR 01/01/2006 002 0 3 37.0
*/
EMPLOYEE
/*
EMPLID EMPL_RCD
001 0
002 0
003 0
003 0
002 0
*/
THe report should therefore look something like
EMPLID DEPTID STD_HRS EFFDT
001 DP1 37.0 01/01/1901
002 DP2b 37.5 01/01/1999
002 DP2b 37.0 01/01/2006
002 DP2a 18.75 01/01/1996
002 DP2a 22.2 01/01/1998
If you need any further details please let me know
code suggestions would be welcome and greatly appreciated
thanks
View 3 Replies
View Related
Jan 23, 2008
Hi. Is there a rownum, rowid, or autonumber in t-sql for SQL Server 2005?
Thanks!
View 10 Replies
View Related
Jul 30, 2004
Hi All....
I have to write one query where i have to display the ID as 1,2 3, 4 in oracle we used to ROWNUM to display ....in MS SQL server is there any property to show???
i have to display like
ID ProgramCount
1 4
2 6
3 5
4 1
5 2
Ashutosh
View 1 Replies
View Related
Oct 13, 2001
hello,
Do we have Rowid or Rownum in SQL Server, or any alternative.
Thanks,
venkat.
View 1 Replies
View Related
Nov 11, 2001
Hello,
How can this query be written in SQLSERVER 7 as it is written in Oracle.
SELECT rownum, column1 from XYZ;
This table returns two columns, first being the auto-generated sequence and second has the values in column1 of XYZ table.
I need to do similar in SQLserver 7 and I am new to it.
Please treat it as urgent..
Thanx
View 2 Replies
View Related
Aug 13, 2007
I apologize in advance, but this post might get somewhat lengthy.
I'm new to the whole pagiong and sorting in SQL Server 2005, and I'm trying to get my SQL to perform in a certain way but can't seem to nail it just down. Hopefully someone can provide some insight or direction. Here's the scoop:
The gui sorts on any column chosen. For example, there's USER, ADDRESS, CITY, STATE, ZIP. The gui allows you to choose how many rows you wish to display per page. If there are 500 rows that meet the search criteria and you choose five pages, there should be 100 records per page. Here's the code:
INSERT INTO #RESULTS
SELECT PY.PaymentId
, PY.PayeeId
, PY.PartyAddressId
, PY.DistributionId
, PY.EntitlementId
, PY.DeliveryTypeEnumItemId
, PY.AccountPaymentId
, PY.ParentPaymentId
, PY.PaymentAmount
, PY.PaymentDate
, PY.PaymentStatusEnumItemId
, PY.PaymentStatusDate
, PY.ReleaseRunId
, PY.ReleaseDate
, PY.AccountTransactionLogId
, PY.AccountStatusEnumItemId
, PY.AccountStatusDate
, PY.AccountPaidAmount
, PY.ReconciledInd
, PY.UndeliverableInd
, PY.ReissueNote
, PY.CreateDate
, PY.CreateId
, PY.ModifiedDate
, PY.ModifiedId
, DS.Description
, AC.Description
, AC.AccountProvider
, AC.AccountId
, PT.Name
, PA.AddressLine1
, PA.AddressLine2
, PA.City
, PA.State
, PA.Zip5
, PA.Zip4
, PE.clm_no
, CM.clmnt_idno
FROM Payment PY (NOLOCK)
JOIN (SELECT DISTINCT
PY.AccountPaymentId,
ROW_NUMBER() OVER(ORDER BY PY.AccountPaymentId) AS RowNum
FROM Payment PY (NOLOCK)) AS SQ
ON (SQ.AccountPaymentId = PY.AccountPaymentId)
JOIN Distribution DS (NOLOCK)
ON (DS.DistributionId = PY.DistributionId)
JOIN Account AC (NOLOCK)
ON (AC.AccountId = DS.AccountId)
JOIN PartyAddress PA (NOLOCK)
ON (PA.PartyAddressId = PY.PartyAddressId)
JOIN Party PT (NOLOCK)
ON (PT.PartyId = PA.PartyId)
JOIN Payee PE (NOLOCK)
ON (PE.PayeeId = PY.PayeeId)
JOIN clm CM (NOLOCK)
ON (CM.clm_no = PE.clm_no)
WHERE RowNum BETWEEN (((@Page * @PageSize) - @PageSize) + 1) AND ((@Page * @PageSize) - @PageSize) + @PageSize
AND ((@PayeeName IS NULL) OR (PT.[Name] LIKE '%' + @PayeeName + '%'))
AND ((@AccountId IS NULL) OR (AC.AccountId = @AccountId))
AND ((@DistributionId IS NULL) OR (DS.DistributionId = @DistributionId))
AND ((@PaymentDate IS NULL) OR (PY.PaymentDate = DATEADD(day, DATEDIFF(day, 0, @PaymentDate), 0))) -- Ignores the time
AND ((@PaymentNumber IS NULL) OR (PY.AccountPaymentId = @PaymentNumber))
AND ((@IsReconciled IS NULL) OR (PY.ReconciledInd = @IsReconciled))
AND ((@AmountIssued IS NULL) OR (PY.PaymentAmount = @AmountIssued))
AND ((@AmountPaid IS NULL) OR (PY.AccountPaidAmount = @AmountPaid))
AND ((@IssueStatus IS NULL) OR (PY.PaymentStatusEnumItemId = @IssueStatus))
AND ((@AccountStatus IS NULL) OR (PY.AccountStatusEnumItemId = @AccountStatus))
ORDER BY AccountPaymentID
--GET A COUNT OF THE ROWS SELECTED
SELECT @TotalRows = Count(*)
FROM Payment PY (NOLOCK)
JOIN (SELECT DISTINCT
PY.PaymentId,
ROW_NUMBER() OVER(ORDER BY PY.PaymentId) AS RowNum
FROM Payment PY (NOLOCK)) AS SQ
ON (SQ.PaymentId = PY.PaymentId)
JOIN Distribution DS (NOLOCK)
ON (DS.DistributionId = PY.DistributionId)
JOIN Account AC (NOLOCK)
ON (AC.AccountId = DS.AccountId)
JOIN PartyAddress PA (NOLOCK)
ON (PA.PartyAddressId = PY.PartyAddressId)
JOIN Party PT (NOLOCK)
ON (PT.PartyId = PA.PartyId)
JOIN Payee PE (NOLOCK)
ON (PE.PayeeId = PY.PayeeId)
JOIN clm CM (NOLOCK)
ON (CM.clm_no = PE.clm_no)
WHERE
((@PayeeName IS NULL) OR (PT.[Name] LIKE '%' + @PayeeName + '%'))
AND ((@AccountId IS NULL) OR (AC.AccountId = @AccountId))
AND ((@DistributionId IS NULL) OR (DS.DistributionId = @DistributionId))
AND ((@PaymentDate IS NULL) OR (PY.PaymentDate = DATEADD(day, DATEDIFF(day, 0, @PaymentDate), 0))) -- Ignores the time
AND ((@PaymentNumber IS NULL) OR (PY.AccountPaymentId = @PaymentNumber))
AND ((@IsReconciled IS NULL) OR (PY.ReconciledInd = @IsReconciled))
AND ((@AmountIssued IS NULL) OR (PY.PaymentAmount = @AmountIssued))
AND ((@AmountPaid IS NULL) OR (PY.AccountPaidAmount = @AmountPaid))
AND ((@IssueStatus IS NULL) OR (PY.PaymentStatusEnumItemId = @IssueStatus))
AND ((@AccountStatus IS NULL) OR (PY.AccountStatusEnumItemId = @AccountStatus))
SET @ORDERBY = ' ORDER BY ' + @SORT --END
--CASE WHEN @Sort IS NULL THEN '' ELSE
EXEC('SELECT * FROM #RESULTS ' + @ORDERBY)
--SET @TOPSQL = 'SELECT TOP ' + Convert(VarChar,@PageSize) + '* FROM #RESULTS ' + @ORDERBY
--SELECT @TOPSQL
--EXEC (@TOPSQL)
SET @PAGES = Round(@totalRows / @PageSize,0,1) + CASE WHEN @TotalRows % @PageSize = 0 THEN 0 ELSE 1 END
-- Return Total number of pages and Total number of Rows
SELECT @PAGES AS PageCount,
@TOTALROWS AS TotalRecords
I get back the rows I'm expecting and it looks fine. What I can't get to happen is the proper sort.
I get back records 1014 records - 1001 through 2014. I choose to display 400 records per page, so ther will be 3 pages total (1001 through 1400 on page 1, 1401 through 1800 on page 2, and 1801 through 2014 on page 3. All the records are sorted by RECORD NUMBER (1000, 1001, etc.)
What I would like to do is when I choose to sort on the column (ASC or DESC),
1.) The entire record set is esssentially retrieved again,
2.) The record set is resorted in the proper order
3.) The record set is redisplayed.
For example, if I'm on Page 2, and I choose to sort in DESCending order, Page 1 would then have records 2014 through 1615, Page 2 would display 1614 through 1215, and page 3 would have 1214 through 1001. Since I was already on Page 2, I would be seeing Page 2 with the new sort. Now when I resort , it just sorts the records on the individual pages, not the entire result set.
Hopefully this all made sense...!
If anyone has any advice or insight, please don't hesitate!
Thank You!!
View 2 Replies
View Related
May 17, 2004
Hi
I have as issue with this rownum.This is supported in different forms in different databases like top in mssql ,limit in mysql and all..i want to genaralise this independent of the type of database because i want to run the query as i wont be knowing the type of the DB used by my user.
can anyone suggest a solution for this ? is there anyway of generating a series of numbers with the query by calling the function in that query repetitively ???
Regards
Sreenath
View 1 Replies
View Related
Mar 31, 2006
do we have any equivalent of rownum and rowid in MS SQL
View 7 Replies
View Related
Aug 14, 2007
I apologize in advance, but this post might get somewhat lengthy.
I'm new to the whole pagiong and sorting in SQL Server 2005, and I'm trying to get my SQL to perform in a certain way but can't seem to nail it just down. Hopefully someone can provide some insight or direction. Here's the scoop:
The gui sorts on any column chosen. For example, there's USER, ADDRESS, CITY, STATE, ZIP. The gui allows you to choose how many rows you wish to display per page. If there are 500 rows that meet the search criteria and you choose five pages, there should be 100 records per page. Here's the code:
Code Snippet
INSERT INTO #RESULTS
SELECT PY.PaymentId
, PY.PayeeId
, PY.PartyAddressId
, PY.DistributionId
, PY.EntitlementId
, PY.DeliveryTypeEnumItemId
, PY.AccountPaymentId
, PY.ParentPaymentId
, PY.PaymentAmount
, PY.PaymentDate
, PY.PaymentStatusEnumItemId
, PY.PaymentStatusDate
, PY.ReleaseRunId
, PY.ReleaseDate
, PY.AccountTransactionLogId
, PY.AccountStatusEnumItemId
, PY.AccountStatusDate
, PY.AccountPaidAmount
, PY.ReconciledInd
, PY.UndeliverableInd
, PY.ReissueNote
, PY.CreateDate
, PY.CreateId
, PY.ModifiedDate
, PY.ModifiedId
, DS.Description
, AC.Description
, AC.AccountProvider
, AC.AccountId
, PT.Name
, PA.AddressLine1
, PA.AddressLine2
, PA.City
, PA.State
, PA.Zip5
, PA.Zip4
, PE.clm_no
, CM.clmnt_idno
FROM Payment PY (NOLOCK)
JOIN (SELECT DISTINCT
PY.AccountPaymentId,
ROW_NUMBER() OVER(ORDER BY PY.AccountPaymentId) AS RowNum
FROM Payment PY (NOLOCK)) AS SQ
ON (SQ.AccountPaymentId = PY.AccountPaymentId)
JOIN Distribution DS (NOLOCK)
ON (DS.DistributionId = PY.DistributionId)
JOIN Account AC (NOLOCK)
ON (AC.AccountId = DS.AccountId)
JOIN PartyAddress PA (NOLOCK)
ON (PA.PartyAddressId = PY.PartyAddressId)
JOIN Party PT (NOLOCK)
ON (PT.PartyId = PA.PartyId)
JOIN Payee PE (NOLOCK)
ON (PE.PayeeId = PY.PayeeId)
JOIN clm CM (NOLOCK)
ON (CM.clm_no = PE.clm_no)
WHERE RowNum BETWEEN (((@Page * @PageSize) - @PageSize) + 1) AND ((@Page * @PageSize) - @PageSize) + @PageSize
AND ((@PayeeName IS NULL) OR (PT.[Name] LIKE '%' + @PayeeName + '%'))
AND ((@AccountId IS NULL) OR (AC.AccountId = @AccountId))
AND ((@DistributionId IS NULL) OR (DS.DistributionId = @DistributionId))
AND ((@PaymentDate IS NULL) OR (PY.PaymentDate = DATEADD(day, DATEDIFF(day, 0, @PaymentDate), 0))) -- Ignores the time
AND ((@PaymentNumber IS NULL) OR (PY.AccountPaymentId = @PaymentNumber))
AND ((@IsReconciled IS NULL) OR (PY.ReconciledInd = @IsReconciled))
AND ((@AmountIssued IS NULL) OR (PY.PaymentAmount = @AmountIssued))
AND ((@AmountPaid IS NULL) OR (PY.AccountPaidAmount = @AmountPaid))
AND ((@IssueStatus IS NULL) OR (PY.PaymentStatusEnumItemId = @IssueStatus))
AND ((@AccountStatus IS NULL) OR (PY.AccountStatusEnumItemId = @AccountStatus))
ORDER BY AccountPaymentID
--GET A COUNT OF THE ROWS SELECTED
SELECT @TotalRows = Count(*)
FROM Payment PY (NOLOCK)
JOIN (SELECT DISTINCT
PY.PaymentId,
ROW_NUMBER() OVER(ORDER BY PY.PaymentId) AS RowNum
FROM Payment PY (NOLOCK)) AS SQ
ON (SQ.PaymentId = PY.PaymentId)
JOIN Distribution DS (NOLOCK)
ON (DS.DistributionId = PY.DistributionId)
JOIN Account AC (NOLOCK)
ON (AC.AccountId = DS.AccountId)
JOIN PartyAddress PA (NOLOCK)
ON (PA.PartyAddressId = PY.PartyAddressId)
JOIN Party PT (NOLOCK)
ON (PT.PartyId = PA.PartyId)
JOIN Payee PE (NOLOCK)
ON (PE.PayeeId = PY.PayeeId)
JOIN clm CM (NOLOCK)
ON (CM.clm_no = PE.clm_no)
WHERE
((@PayeeName IS NULL) OR (PT.[Name] LIKE '%' + @PayeeName + '%'))
AND ((@AccountId IS NULL) OR (AC.AccountId = @AccountId))
AND ((@DistributionId IS NULL) OR (DS.DistributionId = @DistributionId))
AND ((@PaymentDate IS NULL) OR (PY.PaymentDate = DATEADD(day, DATEDIFF(day, 0, @PaymentDate), 0))) -- Ignores the time
AND ((@PaymentNumber IS NULL) OR (PY.AccountPaymentId = @PaymentNumber))
AND ((@IsReconciled IS NULL) OR (PY.ReconciledInd = @IsReconciled))
AND ((@AmountIssued IS NULL) OR (PY.PaymentAmount = @AmountIssued))
AND ((@AmountPaid IS NULL) OR (PY.AccountPaidAmount = @AmountPaid))
AND ((@IssueStatus IS NULL) OR (PY.PaymentStatusEnumItemId = @IssueStatus))
AND ((@AccountStatus IS NULL) OR (PY.AccountStatusEnumItemId = @AccountStatus))
SET @ORDERBY = ' ORDER BY ' + @SORT --END
--CASE WHEN @Sort IS NULL THEN '' ELSE
EXEC('SELECT * FROM #RESULTS ' + @ORDERBY)
--SET @TOPSQL = 'SELECT TOP ' + Convert(VarChar,@PageSize) + '* FROM #RESULTS ' + @ORDERBY
--SELECT @TOPSQL
--EXEC (@TOPSQL)
SET @PAGES = Round(@totalRows / @PageSize,0,1) + CASE WHEN @TotalRows % @PageSize = 0 THEN 0 ELSE 1 END
-- Return Total number of pages and Total number of Rows
SELECT @PAGES AS PageCount,
@TOTALROWS AS TotalRecords
I get back the rows I'm expecting and it looks fine. What I can't get to happen is the proper sort.
I get back records 1014 records - 1001 through 2014. I choose to display 400 records per page, so ther will be 3 pages total (1001 through 1400 on page 1, 1401 through 1800 on page 2, and 1801 through 2014 on page 3. All the records are sorted by RECORD NUMBER (1000, 1001, etc.)
What I would like to do is when I choose to sort on the column (ASC or DESC),
1.) The entire record set is esssentially retrieved again,
2.) The record set is resorted in the proper order
3.) The record set is redisplayed.
For example, if I'm on Page 2, and I choose to sort in DESCending order, Page 1 would then have records 2014 through 1615, Page 2 would display 1614 through 1215, and page 3 would have 1214 through 1001. Since I was already on Page 2, I would be seeing Page 2 with the new sort. Now when I resort , it just sorts the records on the individual pages, not the entire result set.
Hopefully this all made sense...!
If anyone has any advice or insight, please don't hesitate!
Thank You!!
View 11 Replies
View Related
Jan 15, 2001
Is there an equivalent to Oracle's ROWNUM in SQL Server. ROWNUM, when added to a select statement as a column - the query would return an automatic counter, numbering each row returned.
View 1 Replies
View Related
Jun 10, 2000
Hi all
I am new to sqlserve
Is there any equivelant to rownum of oracle.
if not then please can some body gudie me how to give unique
number to each row
like
1 xxx
2 yyy
3 zzz
4 aaa
Thanks pratik
View 2 Replies
View Related
Sep 2, 2004
Hi,
Can any one tell me is there anything in SQL Server thats equivalent
to Oracle's ROWNUM.
Note that the Identity Property or TOP n will not solve my problem.
I want to asign a sequence no. to each row when its being fetched.
For example if in the emp table there are 2000 rows and I write
the following query in Oracle ,
SELECT rownum , empno, empname FROM emp Where rownum < =3
I get the result like this
Rownum----Empno--------------Empname
------------------------------------------
1-----------2345---------------ABCD
2-----------3334---------------EFGH
3-----------4484---------------IJKL
I know I can limit the output rows in SQL Server by using TOP n. But
I also want to generate a sequence no. The identity property of SQL Server
will not be usefull here because my actaul WHERE clause will be more
complex like WHERE resigndate = '01-jan-2004'
Thanks
Asim Naveed
3
View 2 Replies
View Related
Feb 15, 2015
How can I reset the number of Row_Number() if I exceed the number of rows specified.
Example:
Code:
Col1 RowNum
----------------------
ID1 1
ID1 2
ID1 3
ID1 4
ID1 5
ID1 1
ID1 2
ID1 3
ID1 4
In this example, the Row_Number will reset for every 5 items.
View 1 Replies
View Related
Jul 23, 2005
Hello,I would like to know if the equivalent Oracle rownum exist inSQLServer. Here is a sample SQL code to explain what I want to do :selectjobs.name,jobs.job_id,jobs.description,hist.message,hist.step_name,hist.step_id,hist.run_status,hist.run_date,hist.run_time,hist.run_durationfrommsdb.dbo.sysjobs jobs,msdb.dbo.sysjobhistory histwherejobs.job_id=hist.job_idand hist.job_id='E71CCB97-81C3-46E2-83FA-BFFCB66B47F8'order byrun_date, run_timeI just want the first or second row returned by this query. In Oracle Ican simply add rownum=1 or rownum=2 in the where clause to obtain thedesired answer. I don't know how to do in SQLServer.Thank in advance,Pierig.
View 4 Replies
View Related
Sep 23, 2006
hi,
There is no direct equivalent to Oracle's rownum or row id in SQL Server
there is any possiblity are alternate thing is exist then please reply
regards
santosh
View 10 Replies
View Related
Jan 29, 2008
Hi all!
This is my sql statment that works perfectly
select name,id,case when maths>=35 then 'pass' else 'fail' end as maths,
case when science>=35 then 'pass' else 'fail' end as science,
case when tamil>=35 then 'pass' else 'fail' end as tamil ,
case when english>=35 then 'pass' else 'fail' end as english,
case when social>=35 then 'pass' else 'fail' end as social
from student
I dont want to use case in my querey? Is there any way can i replace
case with something?
Thanks in advance!
View 9 Replies
View Related
Aug 6, 2007
I need to implement support for alternate names on the database I’m working on.
When a user looks up: “Antony Bigglesworth” the query would return both: Antony Bigglesworth as well as Tony Bigglesworth, would both exist.
Anyone has a best practice on this or has done this before?
View 8 Replies
View Related
Sep 30, 2006
hi i have a view in oracle. in that i am using decode function.
same query i want to write it in sqlserver. what it is the alternate
to decode.
this is a cross tab query
SELECT code, SUM(DECODE(field1, 4, Present_Value, 0)) AS c1, SUM(DECODE(field1, 5, Present_Value, 0)) AS c2,
SUM(DECODE(field1, 6, Present_Value, 0)) AS c3,SUM(DECODE(field1, 9, Present_Value, 0)) AS c4
FROM (SELECT field1,Code, Present_Value FROM table1) DERIVEDTBL GROUP BY code
thanks
suji
View 8 Replies
View Related
Aug 21, 2007
I've a question regarding SSRS 2005.
Is there an efficient scripting method to update the connection string for ALL reports that reside on a reporting/web server? "(automating the process, rather than having to change the data source for each individual report that resides on that server)".
All suggestions are highly appreciated .
Thanks,
View 3 Replies
View Related
Jul 23, 2005
-- tested schema below ---- create tables --create table tbl_test(serialnumber char(12))gocreate table tbl_test2(serialnumber char(12),exportedflag int)go--insert data --insert into tbl_test2 values ('123456789010',0)insert into tbl_test2 values ('123456789011',0)insert into tbl_test2 values ('123456789012',0)insert into tbl_test2 values ('123456789013',0)insert into tbl_test2 values ('123456789014',0)insert into tbl_test2 values ('123456789015',0)insert into tbl_test2 values ('123456789016',0)insert into tbl_test2 values ('123456789017',0)insert into tbl_test2 values ('123456789018',0)insert into tbl_test2 values ('123456789019',0)insert into tbl_test values ('123456789011')insert into tbl_test values ('123456789012')insert into tbl_test values ('123456789013')insert into tbl_test values ('123456789014')insert into tbl_test values ('123456789015')-- query --Select serialnumber from tbl_test2where serialnumbernot in (select serialnumber from tbl_test) andexportedflag=0This query runs quite fast with only the data above but when bothtables get million plus rows, the query simply bogs down. Is there abetter way to write this query?
View 5 Replies
View Related
Oct 1, 2007
Hi,I have a situation where I am loading data into a stagingtable for multiple data sources. My next step is to pick up therecords from the staging table and compare with the data in thedatabase and based on the certain conditions, decide whether to insertthe data into the database or update an existing record in thedatabase. I have to do this job as an sp and schedule it to run on theserver as per the requirements. I thought that cursors are the onlyoption in this situation. Can anyone suggest if there is any other wayto achieve this in SQL 2005 please.ThanksSeshadri
View 1 Replies
View Related
Jul 27, 2007
I am currently with sql 2k5 and using web assistant to generate some HTML files and email the same automatically to a set of users.
these html files that are generated are processed via a JOB in sql server.
I am in process of replacing of the web assistant procedures.
Is this possible to make this with XQuery of SQL Server 2K5 and convert it into HTML files with Stored Procedure.
Is there any other possible way to do it?
View 1 Replies
View Related
May 21, 2008
Dear All
i want to know some alternate for the below query
"Update STR_RGSTR_DFLT " & _
" Set GST_SVY_FREQ_P = " & iNewSurveyPct & _
" Where dhc_co_c = " & iCo & " and store_i = " & iStore & _
" And RGSTR_PROTO_C not in (0,3,4,8,10,11,12,13)"
in this the values in the where clause 'not in' i.e (0,3,4,8,10,11,12,13) are directly given
but we want some alternate solution.
the entire script is writen in VBScript. these values are already populated in an array like proto_code_ary = {0,3,4,8,10,11,12,13}
shall we use that array directly without hard coding the values in the query?
If any one find a solution please let me know.
Thanks & Regards
S.Manikandan
View 4 Replies
View Related
Oct 25, 2007
In times past I connected my web app to SQL Server by embedding the following in the web.config file: <connectionStrings> <add name="XyzApp_DB" connectionString="Data Source=MyServerSQLExpress;Database=XyzApp;User ID=sa;Password=secret_password"/> </connectionStrings> And it worked fine. But it was pointed out to me that this wasn't a very proper way to do things. So I was advised to set things up with a different connection string: <connectionStrings>
<add name="XyzApp_DB" connectionString="Data
Source=MyServerSQLExpress;Database=XyzApp;User
ID=Xyz_Admin;Password=different_password"/>
</connectionStrings>
To get this to work, I've followed these instructions: A
more secure login than “sa� is required to access your application. In the “connectionStrings� section of
“Web.config� you’ll find a User ID called “Xyz_Admin�. Here are the steps to ensure that your
DB has this login id:
a. Using
the Microsoft SQL Server Management tool, look in the root for the “Security�
folder and open it. Inside that, open
the “Logins� folder.
b. If
“Xyz_Admin� doesn’t exist then right-click on “Logins� and choose “New Login�:
i.
Enter “Xyz_Admin� in the “Login name� textbox.
ii.
Click on “User Mapping� on the left side and in the
‘Map’ column check the box beside “XyzApp�.
iii.
Go back to the “General� page and choose SQL Server
Authentication.
iv.
Specify any secret password you wish.
v.
You can uncheck “Enforce password expiration� if you
wish.
vi.
Specify “XyzApp� as the default database and press
OK.
c.
Open “Databases�, right-click on “XyzApp� and
select “New Query�. Run this query: sp_change_users_login 'update_one',
'xyz_admin', 'xyz_admin'
Now, I was pretty sure that this procedure was working fine but it doesn't seem to work for me today. I know that the client computer I'm using can connect to the DB on the server because I temporarily changed the User Id to "sa" and it connected fine. But when I change it back to "Xyz_Admin" it does not. So I'm thinking that there's something incorrect with the procedure above but I don't know what.Any ideas?Robert W.
View 2 Replies
View Related
Jun 6, 2008
Hi What is the difference between Candidate key , composite key and alternate key. I went through many websites but I didn't get examples. There were only definitions. Can anyone please tell me the site or blogs that elaborate this concept RegardsKaran
View 2 Replies
View Related
Apr 6, 2001
Hi,
What is the alternate for Rowid (in Oracle) in SQL Server ?? Can u tell me ...
urs
VJ
View 2 Replies
View Related
Feb 24, 2000
We just erected a new firewall that only allows PASV FTP. Now, my SQL Server can't call master..xp_cmdshell "ftp ...".
Does anyone know how to make the NT FTP client work in PASV (passive) mode or another FTP client that can be called from xp_cmdshell and works in passive more?
View 1 Replies
View Related
Apr 26, 2004
I need to join a remote table which has 20 million rows to few local tables on my SQL Server. Currently Linked server query is used but it's just hanging for ever..is there any alternative for this?
Thanks.
View 7 Replies
View Related