Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8901973
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T01:29:43+00:00 2026-06-15T01:29:43+00:00

I am doing a matrix multiplication project which involves with matrix So here is

  • 0

I am doing a matrix multiplication project which involves with matrix
So here is my table format:

   create table A ( row integer, col integer, val integer);

What i need to do is to fill in each table with data,
Task 1: create a 200*200 matrix A and all of its element initialized to 1.
That means I would do manually
insert<0,0,1> <0,1,1> <0,2,1> ….<0,199,1>
insert<1,0,1> <1,1,1> <0,2,1> …..<1,199,1> and so

Task 2: create 200*200 matrix A and its diagonal elements are 1’s.

So I am wondering instead of doing this manually, if there anyway to automate initialize all the elements?
The following is an attempt using while loop:

create table A ( row integer, col integer, val integer);
DECLARE @count INT
SET @count = 0
DECLARE @count2 INT
SET @count2 = 0
WHILE (@count < 200)
BEGIN
   WHILE (@count2 <200)
   BEGIN
      INSERT INTO A([row], [col]) VALUES (@count, @counts)
      SET @count2 = (@count2 + 1)
   END
   SET @count = (@count + 1)
END

This the above correct? I am fairly new to sql:(

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T01:29:44+00:00Added an answer on June 15, 2026 at 1:29 am

    Avoid loops and iterative stuff. You’re in SQL Server – think set-based

    Try this

    insert into A( row, col, val )
    select row, col, 1
    from 
    (
            SELECT Row = number from master..spt_values 
            where type='P' and number between 1 and 200
    ) Rows
    CROSS JOIN
    (
            SELECT Col = number from master..spt_values 
            where type='P' and number between 1 and 200
    ) Cols
    

    For your second requirement, you can be lazy and add

    where Row = Col
    

    If it’s a one-off thing then this ought to be ok.

    The master..spt_values bit is all about getting a range of numbers between 1 and 200. You can also have this variation:

    ; WITH cte AS
      (
        SELECT n = number  FROM master..spt_values 
        WHERE type = 'P'  AND  number BETWEEN 1 AND 20
      ) 
    INSERT INTO A ( row, col, val )
    SELECT Rows.n, Cols.n, 1
    FROM
        cte AS Rows
      CROSS JOIN
        cte AS Cols ;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm doing a project for a class which focuses on storing a huge matrix
I'm writing a matrix multiplication method using java. My class is Table which is
I am doing a project which requires me to normalize a sparse NxN matrix.
Hei! I need to optimize some matrix multiplication code in c, and I'm doing
I need to optimize my matrix multiplication by using SIMD/Intel SSE. The example code
I'm doing the matrix multiplication example from the book CUDA C Programming Guide, page
I'm doing a homework that involves multiplying matrix using winthreads. I'm a newbie in
I am doing some matrix multiplication in C and I am trying to compile
I am doing matrix operations on large matrices in my C++ program. I need
Hi i am currently taking a Matrix, P, and doing this P500 = MatrixPower[P,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.