Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 12»»

How to insert empty row Expand / Collapse
Author
Message
Posted Monday, September 10, 2012 4:26 PM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Tuesday, January 28, 2014 3:52 PM
Points: 377, Visits: 685
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.
Post #1357052
Posted Monday, September 10, 2012 5:04 PM


SSC-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Today @ 3:25 PM
Points: 43,008, Visits: 36,164
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 2008, MVP
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

Post #1357058
Posted Monday, September 10, 2012 5:23 PM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Wednesday, August 20, 2014 5:24 AM
Points: 128, Visits: 490
Why not just exclude those fields from the temp table? Do you really need them?

Mark



Post #1357066
Posted Monday, September 10, 2012 6:30 PM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Tuesday, January 28, 2014 3:52 PM
Points: 377, Visits: 685
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.
Post #1357075
Posted Monday, September 10, 2012 6:40 PM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Wednesday, August 20, 2014 5:24 AM
Points: 128, Visits: 490
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



Post #1357079
Posted Monday, September 10, 2012 10:53 PM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Today @ 6:38 AM
Points: 1,945, Visits: 3,001
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. The fact you asked this is a serious problem. You are the kid in Geography class who thinks teh world is flat. Yes, it is that kind of misconception.

However, if all the columns have defaults, then you can write

INSERT INTO Foobar DEFAULT VALUES;


Books in Celko Series for Morgan-Kaufmann Publishing
Analytics and OLAP in SQL
Data and Databases: Concepts in Practice
Data, Measurements and Standards in SQL
SQL for Smarties
SQL Programming Style
SQL Puzzles and Answers
Thinking in Sets
Trees and Hierarchies in SQL
Post #1357133
Posted Tuesday, September 11, 2012 3:39 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Today @ 10:30 AM
Points: 2,848, Visits: 5,095
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.

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!"
(So many miracle inventions provided by MS to us...)

How to post your question to get the best and quick help
Post #1357239
Posted Tuesday, September 11, 2012 8:46 AM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Tuesday, January 28, 2014 3:52 PM
Points: 377, Visits: 685
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.
Post #1357479
Posted Tuesday, September 11, 2012 9:30 AM


Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Today @ 12:58 PM
Points: 3,637, Visits: 7,934
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.
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?

Forum Etiquette: How to post data/code on a forum to get the best help
Post #1357520
Posted Tuesday, September 11, 2012 10:34 AM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Tuesday, January 28, 2014 3:52 PM
Points: 377, Visits: 685
Cannot do that because that will require too many changes in the application.
Post #1357575
« Prev Topic | Next Topic »

Add to briefcase 12»»

Permissions Expand / Collapse