Viewing 15 posts - 1,411 through 1,425 (of 1,438 total)
Here's another version that will give monthly results for each employee
with cte as (
select ID,date_e,val_unit,
row_number() over(partition by ID, convert(char(6),date_e,112) order by date_e desc)...
December 15, 2007 at 11:01 am
Not entirely clear what you want, ID 4807756 seems to turn up twice in your expected results?
Maybe this
with cte as (
select ID,date_e,val_unit,
row_number() over(partition...
December 15, 2007 at 9:45 am
select Email,max(Fname) as Fname
from mytable
group by Email
December 12, 2007 at 7:52 am
> Note: I'm not so sure your ROW_NUMBER (ordinal position logic) is correct as you're ordering on the > Numbers, not their position in the string.
It does work. Try it.
As...
December 11, 2007 at 12:35 pm
You can quite easily get ordinal numbers by doing this.
CREATE FUNCTION Foo
(@p_integer_list VARCHAR(MAX))
RETURNS @return_table TABLE (ROW_NUMBER int IDENTITY(1,1), INTEGER_ID int)
AS
BEGIN;
INSERT INTO @return_table (INTEGER_ID)
SELECT CAST(SUBSTRING(@p_integer_list,
...
December 11, 2007 at 11:18 am
> Personally, I don't like the "numbers" table approach due to limitations on
> the values that can be passed in the delimited string along with duplicate handling.
John,
Can you expand on...
December 11, 2007 at 9:01 am
Using a numbers/sequence table
create procedure [dbo].[_test]
@list varchar(50)
as
WITH CTE AS (
SELECT CAST(SUBSTRING(@list,
...
December 9, 2007 at 3:07 am
with cte as
(select Col0,Col1,Col2,Col3,
row_number() over(partition by Col1 order by Col0) as rn
from #rollupTable)
select Col1,
max(case when rn=1...
November 29, 2007 at 2:02 am
You can script view, functions, stored procedures and triggers using this
select object_definition(object_id)
from sys.objects
where type_desc in ('SQL_SCALAR_FUNCTION',
'SQL_STORED_PROCEDURE',
'SQL_TABLE_VALUED_FUNCTION',
'SQL_TRIGGER',
'VIEW')
There are plenty of scripts around for tables.
November 28, 2007 at 3:00 pm
Maybe this?
WITH CTE AS(
SELECT a.colA,a.colB
FROM MyTable a
WHERE NOT EXISTS(SELECT * FROM MyTable b
WHERE...
November 22, 2007 at 8:27 am
Try adding a materialised path to your CTE
With downline (ConsultantID,ConsultantName,SponsorID,SponsorName,DownLineLevel,FullPath)
AS
(
SELECT A.ConsultantID
,A.FirstName + ' ' + A.LastName as ConsultantName
,A.SponsorID
,(SELECT [FirstName] + ' ' + [LastName] FROM Consultant WHERE ConsultantID = a.SponsorID)
,0...
November 20, 2007 at 9:01 am
Using a calendar table such as found here
you can query for the number of employees hired, terminated and total per month using the query below.
There are plenty...
November 14, 2007 at 7:02 am
select r.value('First_Name[1]','varchar(10)') as First_Name,
r.value('Last_Name[1]','varchar(10)') as Last_Name,
r.value('Age[1]','int') as Age
from @Xmldocument.nodes('/Data/Customer') as d(r)
November 7, 2007 at 6:46 am
select row_number() over(partition by Value order by Value) as ID,
Value
from TableA
November 2, 2007 at 5:11 am
Viewing 15 posts - 1,411 through 1,425 (of 1,438 total)