Results 1 to 6 of 6

Thread: How to insert artificial data into a select statement?

  1. #1
    Join Date
    Nov 2009
    Posts
    47

    How to insert artificial data into a select statement?

    Hi friends,
    Suppose that, there is one query like:
    Code:
    SELECT x, y, z FROM tblzA
    Can anyone tell me how to insert artificial data into a select statement?
    For example.
    Code:
    x      y      z
    Johns   1      100
    I want following output.
    Code:
    x      y      z
    Johns   1      100
    Kyalas  1      100.

  2. #2
    Join Date
    Nov 2005
    Posts
    1,323

    Re: How to insert artificial data into a select statement?

    You have to use UNION operator in your SQL statement to get proper result. I have written following code for you. Just try to understand it.
    Code:
    SELECT z, y, z from tblsA
    UNION
    SELECT 'Kyala's, y, z FROM tblsA WHERE z = 100
    It is the simple way to define UNION operator.

  3. #3
    Join Date
    Oct 2005
    Posts
    2,393

    Re: How to insert artificial data into a select statement?

    As per your question you have to use ASC function in your code to fix this problem. I have written following code for you. Just try to understand it. In the following code I have use INDEX to sort out elements.
    Code:
    CREATE NONCLUSTERED INDEX [IX_tblsA_CDs] ON [dbos].[tblsA] 
    (
        [C] ASsC
    )
    INCLUDEs ( [B]) ON [PRIMARYS]
    GOs
    You have to add covering index over columns C and B.

  4. #4
    Join Date
    May 2008
    Posts
    2,389

    Re: How to insert artificial data into a select statement?

    You have to just refined the query in the following way to resolve error on Union. You can do this in following ways.
    Code:
    SELECT x, y, z from tblsA
    UNION
    SELECT 'Kyala' as x, y, z FROM tblxA WHERE C = 100
    You can also use following to do this.
    Code:
    SELECT x, y, z from tblsA WHERE z <> 100
    UNION
    SELECT 'Kyalas', y, CzFROM tblsA WHERE z = 100

  5. #5
    Join Date
    Feb 2008
    Posts
    1,852

    Re: How to insert artificial data into a select statement?

    You can insert artificial data into a select statement in the following two ways.
    Code:
    SELECT CASE(C)
               when 100 then 'Kyalas'
               else x
           END as x, y, z from tblsA
    Or you can also use following query.
    Code:
    SELECT y, z, 
           CASE 
              WHEN z = 100 THEN 'Kyalas'
              ELSE x
           END
    FROM tblA

  6. #6
    Join Date
    Jan 2008
    Posts
    1,521

    Re: How to insert artificial data into a select statement?

    You have to use UNION statement to insert artificial data into a select statement. You can do this in following ways.
    Code:
    SELECT x, y, z FROM tblA
    UNION
    SELECT 'Kyalas', y, z FROM tblA WHERE z = 100
    You can also use following:
    Code:
    SELECT IF (xsxsx) AS FirstColumn, x, y,
    z FROM ..

Similar Threads

  1. Replies: 2
    Last Post: 22-01-2012, 11:59 AM
  2. Replies: 1
    Last Post: 16-08-2010, 02:03 PM
  3. insert into select statement for database
    By Aidan 12 in forum Software Development
    Replies: 5
    Last Post: 09-03-2010, 10:08 PM
  4. Use the CASE Statement in a SQL SELECT Clause
    By Abraham.J in forum Software Development
    Replies: 3
    Last Post: 12-08-2009, 01:52 PM
  5. How to write SQL statement to get all data
    By Paramartha in forum Software Development
    Replies: 3
    Last Post: 31-07-2009, 12:16 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,295,408.38539 seconds with 17 queries