473,407 Members | 2,326 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,407 software developers and data experts.

Declare an array of int in SQL Server

Hi All,
I want declare an array of int in SQL Server
please help me to convert the following code from VB to TSQL
------------
Dim md_mon(12) As Integer
md_mon(1) = 31
-------------
Thanks
Jul 20 '05 #1
4 71230
There are no arrays in SQLServer. Maybe if you explain your requirements
someone can suggest another alternative.

--
David Portas
SQL Server MVP
--
Jul 20 '05 #2
Majid Mohammadian (Mo***********@yahoo.com) writes:
I want declare an array of int in SQL Server
please help me to convert the following code from VB to TSQL
------------
Dim md_mon(12) As Integer
md_mon(1) = 31
-------------


SQL and Visual Basic are languages that work from very different mindsets,
and for a successful rewrite from VB to SQL it is often best to start from
the beginning. In VB you would typically to things in loops, to iterate
over items in a set of data, but in SQL you should always strive to use
commands that operate on the entire set at the same time. That is when
you actually win performance.

SQL does not have arrays, but there are tables, and tables are a lot broader
concept than array. So in this case:

CREATE TABLE md_mon (monthno int NOT NULL PRIMARY KEY,
noofdays tinyint NOT NULL)

--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 20 '05 #3
If the purpose of your array was to store the number of days in each month
then as an alternative in TSQL you could calculate the number of days for a
given month like this:

DECLARE @dt DATETIME
SET @dt = '20040101' -- January 2004

SELECT DAY(DATEADD(DAY,-1,DATEADD(MONTH,1,DATEADD(DAY,1-DAY(@dt),@dt))))

--
David Portas
SQL Server MVP
--
Jul 20 '05 #4
Erland Sommarskog <so****@algonet.se> wrote in message
SQL does not have arrays, but there are tables, and tables are a lot broader
concept than array. So in this case:

CREATE TABLE md_mon (monthno int NOT NULL PRIMARY KEY,
noofdays tinyint NOT NULL)


FYI: You can also create a table variable, like:

DECLARE @tblMonth TABLE (
MonthNo int,
NumDays int
)

.... and then use it like any real table:

INSERT INTO @tblMonth...
SELECT * FROM @tblMonth...
Jul 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Philipp | last post by:
Hello, I've got a class Lattice which is declared like that: // file: lattice.h class Lattice:public EventChooser{ public: Lattice(LatticeParameters* params); virtual ~Lattice(); //...
2
by: Youn ki beom | last post by:
class A { A() {} }; class B { A* array; A* p_toA;
7
by: b83503104 | last post by:
Previously, when my constructor had no arguments, I used this to declare my objects: MyClass myObject; Now, my constructor has arguments (MyClass::MyClass(int someVariable)), how do I declare...
4
by: Laszlo Szijarto | last post by:
Thank you in advance, I am trying to populate a HashTable object with a value that's an array, but I don't want to put in two lines of code for each entry. rather than saying int value =...
2
by: Petez | last post by:
Hi, I want to declare array of System::Data::DataRow but how? With single variable I write System::Data::DataRow^ aRow but statement System::Data::DataRow^ - not works. System::Data::DataRow* ...
6
by: John A Grandy | last post by:
inside a procedure , i code Dim values(1) As Object .... various other lines of code ... ReDim values(2) As Object
8
by: james | last post by:
Hi, Just looking here: http://msdn2.microsoft.com/en-us/library/9b9dty7d.aspx I can't quite see what I want to do. I want an array of Booleans of length 102, all initially "false". I have this...
3
pentahari
by: pentahari | last post by:
My function is: Function test(optional ByVal arr1() as System.Array) End Function how to declare the array as optional? i know that optional variable must be constant value, but i don't...
4
by: robert.waters | last post by:
I have to parse a binary file having a number of fixed records, each record containing datas in fixed positions. I would like to parse this binary file into an array of structures having members...
1
by: lenniekuah | last post by:
Hullo Good Friends, I need your help, Please Help me. I am using C#Net2008 to develop Window Application. I have not create ARRAY before. The Project Manager asked me to use ARRAY to contain...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.