473,386 Members | 1,699 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

MSSQL hardcoded dataset from select/stored procedure

Plater
7,872 Expert 4TB
So this is kind of an odd request.
I want to be able to return a small "hardcoded" dataset from a stored procedure.
Is that even possible?
I want for example a "GetAvailableTypes" store procedure to return like:

[TypeName]
boat
car
truck
suv

Nomally I would consider hardcoding these values into the software I am writing, but if they need to change, would be easier to just change the storedprocedure and not have to release new software.
I suppose I could just make a table, but I was hoping to avoid doing that as there really is only 10-15 items in this list. Seems like a waste of a table.

Any ideas? Or do I need to just make that table. (In the future, the same storeprocedure could be pulling these values from various other tables, thus the extra abstraction out from the software)
Oct 10 '08 #1
2 7519
ck9663
2,878 Expert 2GB
First to answer your question. Yes, it's possible.

Option 1:
Store those value as a comma separated string then convert that string into a result set table. Here's more on that. But this is a lot of work for your SQL Server.

Option 2:
1. Create a table for these values.
2, Create a view for this table and return the value you need.
3. In the future you can keep the name of the view but the underlying query can be change specially if the values would be coming from different tables.

Option 3:
1.Use this query:
Expand|Select|Wrap|Line Numbers
  1. select 'boat' as [TypeName]
  2. UNION ALL
  3. select 'car'
  4. UNION ALL
  5. select 'truck'
  6. UNION ALL
  7. select 'suv'
2. Create a view or function for this query.
3. In the future you can keep the name of the view/function but the underlying query can be change specially if the values would be coming from different tables.

Happy coding!

-- CK
Oct 10 '08 #2
Delerna
1,134 Expert 1GB
Just some of my thoughts and observations.
(within the context of your post)

Nomally I would consider hardcoding these values into the software I am writing, but if they need to change, would be easier to just change the storedprocedure and not have to release new software.
Great move, I do that sort of thing myself, all the time.
I try hard, never to hard code data like this because, as you say,
It means you don't need to release a new version of your software
just because you added "Hovercraft" to the list.


I suppose I could just make a table, but I was hoping to avoid doing that as there really is only 10-15 items in this list. Seems like a waste of a table.
Hmmmm. I am not disagreeing with you because I am not sure if it is or it isn't.

I've never really hesitated using a table for this purpose.
I have the thought that it is data and tables are best suited to store data.

As a table its easy to allow users to add their own items into the list.
Also you can use the table so that your other database objects (views, sp's, udf's) can automatically handle the addition/removal of items in the list.
Oct 11 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Philip Mette | last post by:
I am in a crunch and need to covert this Oracle statement to MSSQL. Is there any Oracle/MSSQL experts out there that can help me? I do not understand the syntax enough to modify this. Thanks so...
3
by: John Francisco Williams | last post by:
Hi, I searched through this newsgroup looking for an answer for this, but didn't find any (it probably is here. Just didn't find it). I am trying to retrieve information from two related tables,...
3
by: Mike P | last post by:
Is it possible to return a dataset from a stored procedure, or would you need to write the SQL in your .cs file to return the dataset? Any assistance would be really appreciated. Cheers, ...
8
by: Yusuf INCEKARA | last post by:
I have a stored procedure : CREATE PROCEDURE STP_GETSTORELIST @RETCUR CURSOR VARYING OUTPUT AS set @RETCUR = CURSOR FORWARD_ONLY STATIC FOR SELECT ID,STORE_NAME FROM T_INF_STORE ORDER BY...
2
by: a | last post by:
how to send an xml dataset to a Stored Procedure in mssql I have an xml file that I read into a dataset. and I'm trying to use a stored procedure (see SPROC #1 below) that inserts this xml...
2
by: Sandy | last post by:
Hello - I have the following stored procedure and code. I want to put the results in two textboxes. I get to the part where I create the dataset and then I don't know what to do. I tried...
9
by: Nikolay Petrov | last post by:
How to fill DataSet from stored procedure?
5
by: John | last post by:
Hi, I am developing a windows app using C# 2005. This app uses SQL Server or Oracle database depending on the what the user is using. Can I create one typed dataset and use it for SQL Server and...
4
by: sujiforsql | last post by:
i have a stored procedure like below CREATE PROCEDURE display_Products @CategoryID int AS BEGIN DECLARE @authors_cursor CURSOR SET @authors_cursor =CURSOR FAST_FORWARD FOR SELECT TOP 10...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.