Selectall

We Share What We Get

  • Archives

Archive for the ‘MS SQL 2005’ Category

Creating a single field from multiple row results

Posted by selectall on August 9, 2009

select stud_id , group_concat(paper_id) as i from tb
group by id

Original Table:
stud_id paper_id
1 1
1 2
1 3
1 4
2 2
2 3
3 1
4 2

Output:
stud_id paper_id
1 1,2,3,4
2 2,3
3 1
4 2

Posted in MS SQL 2005, Mysql Stuff | Tagged: , , | Leave a Comment »

Add column in query with default value

Posted by selectall on July 8, 2009

SELECT id as student_id,
student_code,
‘Present’ AS attendance_legend_name,
first_name
FROM dbo.ad_student_m

Posted in MS SQL 2005 | Tagged: , , , , , , | Leave a Comment »

Scalar-valued Functions

Posted by selectall on July 4, 2009

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go

CREATE FUNCTION [GetAmount]
(

@Amount decimal,
@Interest decimal,
@Tax decimal
)
RETURNS Decimal(10,2)
AS

BEGIN
DECLARE @TAmount decimal(10,2);
set @TAmount = @Amount + @Interest + @ServiceTax

RETURN @TAmount;
END

Posted in MS SQL 2005 | Tagged: , , | Leave a Comment »

Date Difference in sql2005

Posted by selectall on July 1, 2009

SELECT DATEDIFF(day, DATE_MODIFIED, GETDATE()) AS no_of_days FROM EDITVIEWS_FIELDS

Posted in MS SQL 2005 | Tagged: , , , | Leave a Comment »

Date between two dates in sql 2005

Posted by selectall on July 1, 2009

CONVERT(nvarchar(8), dbo.fs_deposit_m.date_of_deposition, 112) BETWEEN 20090201 AND 20090302

Posted in MS SQL 2005 | Tagged: , , , | Leave a Comment »