Forum Replies Created

Viewing 15 posts - 31 through 45 (of 47 total)

  • RE: generating or populating time dimensions

    Hi,

    Please check the following code. This may help you.

    ------code

    declare @time table (id int identity (1,1),v_time time,v_date date)

    insert into @time

    SELECT

    convert(time,CONVERT(VARCHAR(8),GETDATE(),108)) AS HourMinuteSecond,

    CONVERT(VARCHAR(10),GETDATE(),101) AS DateOnly

    from msdb.INFORMATION_SCHEMA.COLUMNS

    update @time set v_time = DATEADD(mi,15*id,v_time),v_date...

  • RE: to find specific day between two periods

    Try this

    declare @t table (id int identity(1,1),time_stamp date)

    declare @st date,@en date

    select @st = '2011-01-01'

    select @en = '2011-01-20'

    insert into @t

    select convert(varchar(10),@st,110) from INFORMATION_SCHEMA.COLUMNS

    update @t set time_stamp = dateadd(day,id-4,time_stamp)

    select time_stamp from...

  • RE: SQL 2008 query

    -- check this will resolve your solution

    declare @t table (id int identity(1,1),time_stamp date)

    declare @st date,@en date

    select @st = '2011-01-04'

    select @en = '2011-01-08'

    insert into @t

    select convert(varchar(10),GETDATE(),110) from INFORMATION_SCHEMA.COLUMNS

    update @t set...

  • RE: Update statement

    Hi

    declare @t table (sequence_id int,id int,name_key varchar(10),item_name int,rule_id varchar(10))

    insert into @t values (1,6761,'Includes',0, NULL )

    insert into @t values (2,6761,'item',160,'abc')

    insert into @t values (3,6761,'item',163,'xyz')

    insert into @t values (4,6761,'Requires',0,NULL)

    insert into @t...

  • RE: retrieve Column Names from Table and Used in QUERY

    Hi Dave

    I think the query is answered!!!, would you need any more explanation about those 3 lines of code.

    Regards

    Siva Kumar J

  • RE: Remove duplicate records based on record id, annoying GROUP BY statement

    Hi

    Check the following code. This may be useful.

    declare @test_tab table (slno int,name varchar(10))

    insert into @test_tab values (1,'a')

    insert into @test_tab values (1,'b')

    insert into @test_tab values (1,'c')

    insert into @test_tab values (2,'a')

    insert into...

  • RE: retrieve Column Names from Table and Used in QUERY

    Hi

    1. SET @ColName= select function_name (@parameter)

    2. Select @Result=' Select '+ @Colname +' from <my Table> '

    3. execute (@Result)

    Thanks

    Siva Kumar

  • RE: sp_executesql dynamic columns in select statement

    -- This can be used for your solution. But this is not a complete solution.

    -- Chance for having sql injection.

    CREATE PROCEDURE [dbo].[Dynamic_Query_Example] (@p_category varchar(20))

    as

    begin

    declare @v_count int

    declare @sql_query varchar(max), @p_category_select...

  • RE: Using a stored procedure to select columns?

    Hi Paul,

    Thats great. Can u pls give me the best solution to come over the problem.

    Thanks

    Siva Kumar

  • RE: Using a stored procedure to select columns?

    Hi

    May be this one is better solution.

    CREATE PROCEDURE [dbo].[Dynamic_Query_Example] (@p_category varchar(20))

    as

    begin

    declare @v_count int

    declare @sql_query varchar(max), @p_category_select varchar(max)

    select @v_count = count(*) from information_schema.columns where table_name = 'test' and column_name...

  • RE: Using a stored procedure to select columns?

    Hi Paul,

    What happens if I pass the value '1; DROP TABLE EMP; --' as the parameter?

    --------------------------------------------------------------------------------

    Here is an example.

    CREATE TABLE [dbo].[test](

    [id] [int] NOT NULL,

    [dob] [nvarchar](max) NULL,

    [test] [nvarchar](50) NULL

    )

    insert into test...

  • RE: Using a stored procedure to select columns?

    Hi,

    Yes, definetly. You have to use dynamic query. First frame a query using the variables supplied to the procedure. Store query to a variable and then execute that using exec...

  • RE: SQL Help

    ---

  • RE: GetDate() not working

    Hi

    if Database wants to insert the current date, you have to create trigger on that table.

    for ex:

    -- sample code to generate time stamp for each row inserted

    -- create sample table.

    create...

  • RE: I want to get employee name who is drawing the highest sal in each dept

    Hi

    You have to use analytical functions to acheive department wise top salaries. We can achieve top 1..n salaries from the following query. We have to use Dense_Rank() function . Adding...

Viewing 15 posts - 31 through 45 (of 47 total)