How to insert empty row

  • I need to insert empty row in a temp table within a stored procedure. The data types are varchar, varchar, decimal and int. I can enter empty string like '' in varchar, but I do not want to enter null in decimal and int. I want all columns to be blank. How do I do that?

    Thanks.

  • Blank for those data types would be null.

    That said, if you're planning the 'pattern' of inserting a blank row then updating it to actual values, please reconsider. It can cause huge fragmentation problems as well as being a rather poor design pattern. Just insert the real values.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • Why not just exclude those fields from the temp table? Do you really need them?

    Mark

  • With new security featues of Excel, if an Excel file is small size then one cannot programmatically open the file otherwise it errors out. So if the file size is small, I want to add empty records in stored proc, which will feed the data to excel thru my application. If there are zeros in rows, then the users are getting confused. What could be the solution to this?

    Thanks.

  • Old Hand,

    I've seen size issues when the data in the excel spreadsheet it too large but never too small.

    How are you creating the file and how are you opening it?

    Mark

  • CELKO (9/10/2012)


    I need to insert empty row in a temp table within a stored procedure.

    Where is the DDL? There is no such concept in RDBMS.

    ...

    What kind of concept is missing here?

    Why is it a problem to have a temp table with empty rows?

    It can be used to build cartesian products, and it's quite easy to populate it, for example:

    -- create temp table and populate it with 10 empty rows

    SELECT TOP 10 CAST(null AS CHAR(1)) c INTO #t

    FROM sys.columns

    -- Select each row from MyTable as many times (10) as many empty rows found in #t

    SELECT t.*

    FROM dbo.MyTable

    CROSS JOIN #t

    See? A bit of creativity and concept flies. :hehe:

    However, I am sure it's not what OP does need it for...

    _____________________________________________
    "The only true wisdom is in knowing you know nothing"
    "O skol'ko nam otkrytiy chudnyh prevnosit microsofta duh!":-D
    (So many miracle inventions provided by MS to us...)

    How to post your question to get the best and quick help[/url]

  • I am creating and then opening the excel file in MVC application. If the file is not small, then it opens without problems. But if it is small, it errors out. I tried adding more rows with zero values in decimal and int fields, and the same file opens without any problems. The only problem now is when the users sees zeros, they get confused.

  • Why don't you send all your values as varchar using cast/convert?

    Excel will convert everything that looks like a number to a "number type" and leave text as general.

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • Cannot do that because that will require too many changes in the application.

  • ramadesai108 (9/11/2012)


    Cannot do that because that will require too many changes in the application.

    Why? How are you populating your Excel file?

    Are you sure this is the correct approach? I'm not sure that creating larger files is a good practice. Are you sure you can't change that in the options?

    Another option would be use an older version of Excel to create the file :hehe:

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • Add a column named IgnoreThisRow, and set it to true for empty rows, false for real rows.

  • The site is used by over 100,000 users. Version of Excel cannot change.

  • ramadesai108 (9/12/2012)


    The site is used by over 100,000 users. Version of Excel cannot change.

    There seems to be something fundamentally poorly designed given all the challenges you are facing here. You have a web site with over 100,000 users all locked into a specific version of Excel? You are asking for problems with that.

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/

  • How are you generating this excel? via SQL? and getting it by file path to the web? what error are you seeing, exactly ? If you can manage to input lines with 0, can't you input lines with a single space?

    I think we need more info on your problem

  • Using .Net app to connect to sql and get the data using store proc, creating excel file in the app and opening the file. There are no problems with this process. It is just that when the excel file that is produced is small size, excel does not open the file. This is a known issue and the workaround is to create empty rows in excel so that it increases the file and opens the file without any issues.

Viewing 15 posts - 1 through 14 (of 14 total)

You must be logged in to reply to this topic. Login to reply